Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ayab-esp32 Build environment #182

Closed
wants to merge 12 commits into from
6 changes: 0 additions & 6 deletions .gitmodules

This file was deleted.

57 changes: 57 additions & 0 deletions boards/ayab-esp32.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"build": {
"arduino":{
"ldscript": "esp32s3_out.ld",
"partitions": "partitions-4MB-tinyuf2.csv"
},
"core": "esp32",
"extra_flags": [
"-DARDUINO_USB_CDC_ON_BOOT=1",
"-DARDUINO_RUNNING_CORE=1",
"-DARDUINO_EVENT_RUNNING_CORE=1",
"-DBOARD_HAS_PSRAM"
],
"f_cpu": "240000000L",
"f_flash": "80000000L",
"flash_mode": "qio",
"hwids": [
[
"0x239A",
"0x811B"
],
[
"0x239A",
"0x011B"
],
[
"0x239A",
"0x811C"
]
],
"mcu": "esp32s3",
"variant": "esp32s3"
},
"connectivity": [
"bluetooth",
"wifi"
],
"debug": {
"openocd_target": "esp32s3.cfg"
},
"frameworks": [
"arduino",
"espidf"
],
"name": "AYAB-ESP32",
"upload": {
"flash_size": "4MB",
"maximum_ram_size": 327680,
"maximum_size": 4194304,
"use_1200bps_touch": true,
"wait_for_upload_port": true,
"require_upload_port": true,
"speed": 460800
},
"url": "https://ayab-knitting.com",
"vendor": "AllYarnsAreBeautiful"
}
1 change: 0 additions & 1 deletion lib/Adafruit_MCP23008
Submodule Adafruit_MCP23008 deleted from 05fc9b
1 change: 0 additions & 1 deletion lib/PacketSerial
Submodule PacketSerial deleted from 44c5b0
11 changes: 9 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = uno
default_envs = uno, ayab-esp32

[env]
framework = arduino
extra_scripts =
pre:scripts/preBuild.py
pre:scripts/preBuild.py
lib_deps =
adafruit/Adafruit MCP23017 Arduino Library@^2.3.2
bakercp/PacketSerial@^1.4.0

[env:uno]
platform = atmelavr
board = uno

[env:ayab-esp32]
platform = espressif32
board = ayab-esp32
72 changes: 62 additions & 10 deletions src/ayab/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@

#include <Arduino.h>

#ifdef DBG_NOMACHINE // Turn on to use DBG_BTN_PIN as EOL Trigger
constexpr uint8_t DBG_BTN_PIN = 7; // DEBUG BUTTON
#endif

// TODO(Who?): Optimize Delay for various Arduino Models (does ESP32 need this? Probably no?)
constexpr uint16_t START_KNITTING_DELAY = 2000U; // ms

// Determine board type
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
// Arduino Uno

#define HAS_MCP23008
constexpr uint8_t I2Caddr_sol1_8 = 0x0U; ///< I2C Address of solenoids 1 - 8
constexpr uint8_t I2Caddr_sol9_16 = 0x1U; ///< I2C Address of solenoids 9 - 16

// Pin Assignments
constexpr uint8_t EOL_PIN_R = A0; // Analog
constexpr uint8_t EOL_PIN_L = A1; // Analog
Expand All @@ -39,20 +54,57 @@ constexpr uint8_t LED_PIN_A = 5; // green LED
constexpr uint8_t LED_PIN_B = 6; // yellow LED

constexpr uint8_t PIEZO_PIN = 9;
#elif defined(CONFIG_IDF_TARGET_ESP32S3)// ESP32-S3 (AYAB-ESP32)

#ifdef DBG_NOMACHINE // Turn on to use DBG_BTN_PIN as EOL Trigger
constexpr uint8_t DBG_BTN_PIN = 7; // DEBUG BUTTON
#endif
#define HAS_MCP23017
constexpr uint8_t MCP23017_ADDR_0 = 0x0U; // I2C address of expander on ayab-esp32 (16-wide)

constexpr uint8_t I2Caddr_sol1_8 = 0x0U; ///< I2C Address of solenoids 1 - 8
constexpr uint8_t I2Caddr_sol9_16 = 0x1U; ///< I2C Address of solenoids 9 - 16
// Knitting machine control
constexpr uint8_t EOL_PIN_R_N = 3; // Right EOL marker, each polarity.
constexpr uint8_t EOL_PIN_R_S = 4;

// TODO(Who?): Optimize Delay for various Arduino Models
constexpr uint16_t START_KNITTING_DELAY = 2000U; // ms
constexpr uint8_t EOL_PIN_L_N = 1; // Left EOL marker, each polarity.
constexpr uint8_t EOL_PIN_L_S = 2;

constexpr uint8_t ENC_PIN_A = 5; // Carriage movement A
constexpr uint8_t ENC_PIN_B = 6; // Carriage movement B
constexpr uint8_t ENC_PIN_C = 7; // Carriage belt phase alignment.

constexpr uint8_t MCP_SDA_PIN = 8; // Internal I2C bus with MCP GPIO expander.
constexpr uint8_t MCP_SCL_PIN = 9; // I2C0

// Communication busses
constexpr uint8_t SPI_PIN_COPI = 12; // Internal SPI bus for future display.
constexpr uint8_t SPI_PIN_CIPO = 11; // SPI0
constexpr uint8_t SPI_PIN_SCK = 13;
constexpr uint8_t SPI_PIN_CS = 10;

constexpr uint8_t UART_PIN_TX = 43; // External bus for debugging and/or user.
constexpr uint8_t UART_PIN_RX = 44; // UART0

constexpr uint8_t I2C_PIN_SDA = 15; // External bus for user applications.
constexpr uint8_t I2C_PIN_SCL = 16; // I2C1

// Misc I/O
constexpr uint8_t LED_PIN_R = 33;
constexpr uint8_t LED_PIN_G = 34;
constexpr uint8_t LED_PIN_B = 35;

constexpr uint8_t PIEZO_PIN = 38;

// User I/O
constexpr uint8_t USER_BUTTON = 36;

constexpr uint8_t USER_PIN_14 = 14; // Should these actually be like USER_0... etc?
constexpr uint8_t USER_PIN_17 = 17; // And then on the silk/ enclosure we put friendly numbers (0..8) instead of GPIO name?
constexpr uint8_t USER_PIN_18 = 18;
constexpr uint8_t USER_PIN_21 = 21;

constexpr uint8_t USER_PIN_39 = 39;
constexpr uint8_t USER_PIN_40 = 40;
constexpr uint8_t USER_PIN_41 = 41;
constexpr uint8_t USER_PIN_42 = 42;

// Determine board type
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
// Arduino Uno
#else
#error "untested board"
#endif
Expand Down
3 changes: 1 addition & 2 deletions src/ayab/encoders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
* http://ayab-knitting.com
*/

#include "board.h"
#include <Arduino.h>

#include "board.h"
#include "encoders.h"


Expand Down
14 changes: 7 additions & 7 deletions src/ayab/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
// Global definitions: references elsewhere must use `extern`.
// Each of the following is a pointer to a singleton class
// containing static methods.
constexpr GlobalBeeper *beeper;
constexpr GlobalCom *com;
constexpr GlobalEncoders *encoders;
constexpr GlobalFsm *fsm;
constexpr GlobalKnitter *knitter;
constexpr GlobalSolenoids *solenoids;
constexpr GlobalTester *tester;
constexpr GlobalBeeper *beeper = 0;
constexpr GlobalCom *com = 0;
constexpr GlobalEncoders *encoders = 0;
constexpr GlobalFsm *fsm = 0;
constexpr GlobalKnitter *knitter = 0;
constexpr GlobalSolenoids *solenoids = 0;
constexpr GlobalTester *tester = 0;

// Initialize static members.
// Each singleton class contains a pointer to a static instance
Expand Down
32 changes: 30 additions & 2 deletions src/ayab/solenoids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,23 @@
* \brief Initialize I2C connection for solenoids.
*/
void Solenoids::init() {
mcp_0.begin(I2Caddr_sol1_8);
mcp_1.begin(I2Caddr_sol9_16);
#ifdef HAS_MCP23008
mcp_0.begin_I2C(I2Caddr_sol1_8);
mcp_1.begin_I2C(I2Caddr_sol9_16);

for (uint8_t i = 0; i < SOLENOID_BUFFER_SIZE / 2; i++) {
mcp_0.pinMode(i, OUTPUT);
mcp_1.pinMode(i, OUTPUT);
}

#elif HAS_MCP23017
mcp.begin_I2C(MCP23017_ADDR_0);

for (uint8_t i = 0; i < SOLENOID_BUFFER_SIZE; i++){
mcp.pinMode(i, OUTPUT);
}

#endif
solenoidState = 0x0000U;
}

Expand Down Expand Up @@ -95,7 +105,25 @@ void Solenoids::setSolenoids(uint16_t state) {
// GCOVR_EXCL_START
void Solenoids::write(uint16_t newState) {
(void)newState;
#if defined(HAS_MCP23008)
mcp_0.writeGPIO(lowByte(newState));
mcp_1.writeGPIO(highByte(newState));

#elif defined(HAS_MCP23017)
// We need to shuffle the bits around due to hardware layout.
// GPA0..8 => solenoid 8-F
// GPB0..8 => solenoid 7-0
// Adafruit mapping: GPA0...8, GPB0..8 => 0..15
uint16_t bankA = (newState >> 8); // map solenoids 8..F to 0..7 GPIO A

uint16_t bankB = 0;
for(uint8_t i = 0; i < 8; i++){
// Need to reverse the bits of the upper byte (which is located in the lower byte)
bankB[i+8] = (newState >> (7-i)) & 0x01;
}

mcp.writeGPIOAB(bankA & bankB);

#endif
}
// GCOVR_EXCL_STOP
11 changes: 8 additions & 3 deletions src/ayab/solenoids.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
#include "board.h"
#include "encoders.h"
#include <Arduino.h>
#include <Adafruit_MCP23008.h>
#include <Adafruit_MCP23X08.h>
#include <Adafruit_MCP23X17.h>
#include <Wire.h>

// Different machines have a different number of solenoids.
Expand Down Expand Up @@ -84,8 +85,12 @@ class Solenoids : public SolenoidsInterface {
uint16_t solenoidState = 0x0000U;
void write(uint16_t state);

Adafruit_MCP23008 mcp_0 = Adafruit_MCP23008();
Adafruit_MCP23008 mcp_1 = Adafruit_MCP23008();
#if defined(HAS_MCP23008)
Adafruit_MCP23X08 mcp_0 = Adafruit_MCP23X08();
Adafruit_MCP23X08 mcp_1 = Adafruit_MCP23X08();
#elif defined(HAS_MCP23017)
Adafruit_MCP23X17 mcp = Adafruit_MCP23X17();
#endif
};

#endif // SOLENOIDS_H_
2 changes: 1 addition & 1 deletion static_analysis.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
clang-tidy src/ayab/$1.cpp --fix -- -isystem /usr/share/arduino/hardware/arduino/cores/arduino/ -isystem /usr/lib/avr/include/ -isystem /usr/share/arduino/hardware/arduino/variants/standard -isystem libraries/Adafruit_MCP23008/ -isystem /usr/share/arduino/libraries/Wire/ -isystem libraries/PacketSerial/src/ -DCLANG_TIDY "${@:2}"
clang-tidy src/ayab/$1.cpp --fix -- -isystem /usr/share/arduino/hardware/arduino/cores/arduino/ -isystem /usr/lib/avr/include/ -isystem /usr/share/arduino/hardware/arduino/variants/standard -isystem /usr/share/arduino/libraries/Wire/ -DCLANG_TIDY "${@:2}"
Loading