diff --git a/src/hal/avr/shr16.cpp b/src/hal/avr/shr16.cpp index 24326cd..28565ee 100644 --- a/src/hal/avr/shr16.cpp +++ b/src/hal/avr/shr16.cpp @@ -13,22 +13,22 @@ SHR16 shr16; void SHR16::Init() { using namespace hal::gpio; - gpio::Init(GPIO_pin(SHR16_DATA), GPIO_InitTypeDef(Mode::output, Level::low)); - gpio::Init(GPIO_pin(SHR16_LATCH), GPIO_InitTypeDef(Mode::output, Level::high)); - gpio::Init(GPIO_pin(SHR16_CLOCK), GPIO_InitTypeDef(Mode::output, Level::low)); + gpio::Init(SHR16_DATA, GPIO_InitTypeDef(Mode::output, Level::low)); + gpio::Init(SHR16_LATCH, GPIO_InitTypeDef(Mode::output, Level::high)); + gpio::Init(SHR16_CLOCK, GPIO_InitTypeDef(Mode::output, Level::low)); Write(0); } void SHR16::Write(uint16_t v) { using namespace hal::gpio; - WritePin(GPIO_pin(SHR16_LATCH), Level::low); + WritePin(SHR16_LATCH, Level::low); for (uint16_t m = 0x8000; m; m >>= 1) { - WritePin(GPIO_pin(SHR16_DATA), (Level)((m & v) != 0)); - WritePin(GPIO_pin(SHR16_CLOCK), Level::high); - WritePin(GPIO_pin(SHR16_CLOCK), Level::low); + WritePin(SHR16_DATA, (Level)((m & v) != 0)); + WritePin(SHR16_CLOCK, Level::high); + WritePin(SHR16_CLOCK, Level::low); } - WritePin(GPIO_pin(SHR16_LATCH), Level::high); + WritePin(SHR16_LATCH, Level::high); shr16_v = v; } diff --git a/src/hal/gpio.h b/src/hal/gpio.h index aceaa17..fc677bf 100644 --- a/src/hal/gpio.h +++ b/src/hal/gpio.h @@ -40,11 +40,10 @@ struct GPIO_InitTypeDef { }; struct GPIO_pin { + // No constructor here in order to allow brace-initialization in old + // gcc versions/standards GPIO_TypeDef *const port; const uint8_t pin; - inline GPIO_pin(GPIO_TypeDef *const port, const uint8_t pin) - : port(port) - , pin(pin) {}; }; __attribute__((always_inline)) inline void WritePin(const GPIO_pin portPin, Level level) { diff --git a/src/main.cpp b/src/main.cpp index b5995c1..27c5d5b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -110,8 +110,8 @@ void setup() { // @@TODO if the shift register doesn't work we really can't signalize anything, only internal variables will be accessible if the UART works hu::USART::USART_InitTypeDef usart_conf = { - .rx_pin = gpio::GPIO_pin(GPIOD, 2), - .tx_pin = gpio::GPIO_pin(GPIOD, 3), + .rx_pin = USART_RX, + .tx_pin = USART_TX, .baudrate = 115200, }; hu::usart1.Init(&usart_conf); @@ -121,10 +121,10 @@ void setup() { // @@TODO if both shift register and the UART are dead, we are sitting ducks :( spi::SPI_InitTypeDef spi_conf = { - .miso_pin = gpio::GPIO_pin(TMC2130_SPI_MISO_PIN), - .mosi_pin = gpio::GPIO_pin(TMC2130_SPI_MOSI_PIN), - .sck_pin = gpio::GPIO_pin(TMC2130_SPI_SCK_PIN), - .ss_pin = gpio::GPIO_pin(TMC2130_SPI_SS_PIN), + .miso_pin = TMC2130_SPI_MISO_PIN, + .mosi_pin = TMC2130_SPI_MOSI_PIN, + .sck_pin = TMC2130_SPI_SCK_PIN, + .ss_pin = TMC2130_SPI_SS_PIN, .prescaler = 2, //4mhz .cpha = 1, .cpol = 1, diff --git a/src/pins.h b/src/pins.h index 468cad1..b983596 100644 --- a/src/pins.h +++ b/src/pins.h @@ -2,12 +2,16 @@ #include "hal/gpio.h" /// pin definitions +#define GPIO_PIN(port, pin) hal::gpio::GPIO_pin{port, pin} -#define TMC2130_SPI_MISO_PIN GPIOB, 3 -#define TMC2130_SPI_MOSI_PIN GPIOB, 2 -#define TMC2130_SPI_SCK_PIN GPIOB, 1 -#define TMC2130_SPI_SS_PIN GPIOB, 0 +#define TMC2130_SPI_MISO_PIN GPIO_PIN(GPIOB, 3) +#define TMC2130_SPI_MOSI_PIN GPIO_PIN(GPIOB, 2) +#define TMC2130_SPI_SCK_PIN GPIO_PIN(GPIOB, 1) +#define TMC2130_SPI_SS_PIN GPIO_PIN(GPIOB, 0) -#define SHR16_DATA GPIOB, 5 ///DS -#define SHR16_LATCH GPIOB, 6 ///STCP -#define SHR16_CLOCK GPIOC, 7 ///SHCP +#define SHR16_DATA GPIO_PIN(GPIOB, 5) ///DS +#define SHR16_LATCH GPIO_PIN(GPIOB, 6) ///STCP +#define SHR16_CLOCK GPIO_PIN(GPIOC, 7) ///SHCP + +#define USART_RX GPIO_PIN(GPIOD, 2) +#define USART_TX GPIO_PIN(GPIOD, 3)