From 5f407124193b3f1dd552ef1987084e1b647186e3 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 19:20:46 -0400 Subject: [PATCH 01/38] Update DaisySeed to use GPIO --- src/daisy_seed.cpp | 67 +++++++++++++++++++++++----------------------- src/daisy_seed.h | 2 +- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/daisy_seed.cpp b/src/daisy_seed.cpp index f121d94f6..fbc7a0200 100644 --- a/src/daisy_seed.cpp +++ b/src/daisy_seed.cpp @@ -7,11 +7,11 @@ extern "C" using namespace daisy; -#define SEED_LED_PORT DSY_GPIOC -#define SEED_LED_PIN 7 +constexpr GPIOPort SEED_LED_PORT = PORTC; +constexpr uint8_t SEED_LED_PIN = 7; -#define SEED_TEST_POINT_PORT DSY_GPIOG -#define SEED_TEST_POINT_PIN 14 +constexpr GPIOPort SEED_TEST_POINT_PORT = PORTG; +constexpr uint8_t SEED_TEST_POINT_PIN = 14; #ifndef SEED_REV2 const dsy_gpio_pin seedgpio[33] = { @@ -105,13 +105,14 @@ void DaisySeed::Init(bool boost) ConfigureQspi(); // Configure the built-in GPIOs. - led.pin.port = SEED_LED_PORT; - led.pin.pin = SEED_LED_PIN; - led.mode = DSY_GPIO_MODE_OUTPUT_PP; - testpoint.pin.port = SEED_TEST_POINT_PORT; - testpoint.pin.pin = SEED_TEST_POINT_PIN; - testpoint.mode = DSY_GPIO_MODE_OUTPUT_PP; + GPIO::Config &led_config = led.GetConfig(); + GPIO::Config &testpoint_config = testpoint.GetConfig(); + led_config.pin = Pin(SEED_LED_PORT, SEED_LED_PIN); + led_config.mode = GPIO::Mode::OUTPUT; + + testpoint_config.pin = Pin(SEED_TEST_POINT_PORT, SEED_TEST_POINT_PIN); + testpoint_config.mode = GPIO::Mode::OUTPUT; auto memory = System::GetProgramMemoryRegion(); @@ -125,8 +126,8 @@ void DaisySeed::Init(bool boost) if(memory == System::MemoryRegion::INTERNAL_FLASH) { - dsy_gpio_init(&led); - dsy_gpio_init(&testpoint); + led.Init(led.GetConfig()); + testpoint.Init(testpoint.GetConfig()); sdram_handle.Init(); } @@ -231,12 +232,12 @@ float DaisySeed::AudioCallbackRate() const void DaisySeed::SetLed(bool state) { - dsy_gpio_write(&led, state); + led.Write(state); } void DaisySeed::SetTestPoint(bool state) { - dsy_gpio_write(&testpoint, state); + testpoint.Write(state); } const SaiHandle& DaisySeed::AudioSaiHandle() const @@ -251,12 +252,12 @@ void DaisySeed::ConfigureQspi() qspi_config.device = QSPIHandle::Config::Device::IS25LP064A; qspi_config.mode = QSPIHandle::Config::Mode::MEMORY_MAPPED; - qspi_config.pin_config.io0 = dsy_pin(DSY_GPIOF, 8); - qspi_config.pin_config.io1 = dsy_pin(DSY_GPIOF, 9); - qspi_config.pin_config.io2 = dsy_pin(DSY_GPIOF, 7); - qspi_config.pin_config.io3 = dsy_pin(DSY_GPIOF, 6); - qspi_config.pin_config.clk = dsy_pin(DSY_GPIOF, 10); - qspi_config.pin_config.ncs = dsy_pin(DSY_GPIOG, 6); + qspi_config.pin_config.io0 = Pin(PORTF, 8); + qspi_config.pin_config.io1 = Pin(PORTF, 9); + qspi_config.pin_config.io2 = Pin(PORTF, 7); + qspi_config.pin_config.io3 = Pin(PORTF, 6); + qspi_config.pin_config.clk = Pin(PORTF, 10); + qspi_config.pin_config.ncs = Pin(PORTG, 6); } void DaisySeed::ConfigureAudio() { @@ -268,9 +269,9 @@ void DaisySeed::ConfigureAudio() sai_config.bit_depth = SaiHandle::Config::BitDepth::SAI_24BIT; sai_config.a_sync = SaiHandle::Config::Sync::MASTER; sai_config.b_sync = SaiHandle::Config::Sync::SLAVE; - sai_config.pin_config.fs = {DSY_GPIOE, 4}; - sai_config.pin_config.mclk = {DSY_GPIOE, 2}; - sai_config.pin_config.sck = {DSY_GPIOE, 5}; + sai_config.pin_config.fs = Pin(PORTE, 4); + sai_config.pin_config.mclk = Pin(PORTE, 2); + sai_config.pin_config.sck = Pin(PORTE, 5); // Device-based Init switch(CheckBoardVersion()) @@ -279,15 +280,15 @@ void DaisySeed::ConfigureAudio() { // Data Line Directions sai_config.a_dir = SaiHandle::Config::Direction::RECEIVE; - sai_config.pin_config.sa = {DSY_GPIOE, 6}; + sai_config.pin_config.sa = Pin(PORTE, 6); sai_config.b_dir = SaiHandle::Config::Direction::TRANSMIT; - sai_config.pin_config.sb = {DSY_GPIOE, 3}; + sai_config.pin_config.sb = Pin(PORTE, 3); I2CHandle::Config i2c_config; i2c_config.mode = I2CHandle::Config::Mode::I2C_MASTER; i2c_config.periph = I2CHandle::Config::Peripheral::I2C_2; i2c_config.speed = I2CHandle::Config::Speed::I2C_400KHZ; - i2c_config.pin_config.scl = {DSY_GPIOH, 4}; - i2c_config.pin_config.sda = {DSY_GPIOB, 11}; + i2c_config.pin_config.scl = Pin(PORTH, 4); + i2c_config.pin_config.sda = Pin(PORTB, 11); I2CHandle i2c_handle; i2c_handle.Init(i2c_config); Wm8731::Config codec_cfg; @@ -300,9 +301,9 @@ void DaisySeed::ConfigureAudio() { // Data Line Directions sai_config.a_dir = SaiHandle::Config::Direction::TRANSMIT; - sai_config.pin_config.sa = {DSY_GPIOE, 6}; + sai_config.pin_config.sa = Pin(PORTE, 6); sai_config.b_dir = SaiHandle::Config::Direction::RECEIVE; - sai_config.pin_config.sb = {DSY_GPIOE, 3}; + sai_config.pin_config.sb = Pin(PORTE, 3); /** PCM3060 disable deemphasis pin */ GPIO deemp; deemp.Init(Pin(PORTB, 11), GPIO::Mode::OUTPUT); @@ -314,11 +315,11 @@ void DaisySeed::ConfigureAudio() { // Data Line Directions sai_config.a_dir = SaiHandle::Config::Direction::TRANSMIT; - sai_config.pin_config.sa = {DSY_GPIOE, 6}; + sai_config.pin_config.sa = Pin(PORTE, 6); sai_config.b_dir = SaiHandle::Config::Direction::RECEIVE; - sai_config.pin_config.sb = {DSY_GPIOE, 3}; - dsy_gpio_pin codec_reset_pin; - codec_reset_pin = {DSY_GPIOB, 11}; + sai_config.pin_config.sb = Pin(PORTE, 3); + + constexpr Pin codec_reset_pin = Pin(PORTB, 11); Ak4556::Init(codec_reset_pin); } break; diff --git a/src/daisy_seed.h b/src/daisy_seed.h index cc15472bd..95ec8b771 100644 --- a/src/daisy_seed.h +++ b/src/daisy_seed.h @@ -145,7 +145,7 @@ class DaisySeed AdcHandle adc; /**< & */ DacHandle dac; UsbHandle usb_handle; /**< & */ - dsy_gpio led, testpoint; + GPIO led, testpoint; System system; /** Internal indices for DaisySeed-equivalent devices From f13f0fa23b193a5275a61d0807a7a08ce96ffcd1 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 19:22:45 -0400 Subject: [PATCH 02/38] Update DaisyPatch to use GPIO --- src/daisy_patch.cpp | 5 +---- src/daisy_patch.h | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/daisy_patch.cpp b/src/daisy_patch.cpp index 6e070a29b..cf430575e 100644 --- a/src/daisy_patch.cpp +++ b/src/daisy_patch.cpp @@ -286,10 +286,7 @@ void DaisyPatch::InitEncoder() void DaisyPatch::InitGates() { // Gate Output - gate_output.pin = PIN_GATE_OUT; - gate_output.mode = DSY_GPIO_MODE_OUTPUT_PP; - gate_output.pull = DSY_GPIO_NOPULL; - dsy_gpio_init(&gate_output); + gate_output.Init(PIN_GATE_OUT, GPIO::Mode::OUTPUT); // Gate Inputs gate_input[GATE_IN_1].Init(PIN_GATE_IN_1); diff --git a/src/daisy_patch.h b/src/daisy_patch.h index 68b16c500..4988040d6 100644 --- a/src/daisy_patch.h +++ b/src/daisy_patch.h @@ -122,7 +122,7 @@ class DaisyPatch OledDisplay display; /**< & */ // TODO: Add class for Gate output - dsy_gpio gate_output; /**< & */ + GPIO gate_output; /**< & */ private: From 82b06899e556093a915096b410635c3a0fc7fcd9 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 19:23:16 -0400 Subject: [PATCH 03/38] Update daisy::patch_sm to use GPIO --- src/daisy_patch_sm.cpp | 18 ++++-------------- src/daisy_patch_sm.h | 4 ++-- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/daisy_patch_sm.cpp b/src/daisy_patch_sm.cpp index b68fdb5f6..4908f7ba4 100644 --- a/src/daisy_patch_sm.cpp +++ b/src/daisy_patch_sm.cpp @@ -321,23 +321,13 @@ namespace patch_sm } /** Fixed-function Digital I/O */ - user_led.mode = DSY_GPIO_MODE_OUTPUT_PP; - user_led.pull = DSY_GPIO_NOPULL; - user_led.pin = PIN_USER_LED; - dsy_gpio_init(&user_led); + user_led.Init(PIN_USER_LED, GPIO::Mode::OUTPUT); //gate_in_1.Init((dsy_gpio_pin *)&DaisyPatchSM::B10); gate_in_1.Init(B10); gate_in_2.Init(B9); - gate_out_1.mode = DSY_GPIO_MODE_OUTPUT_PP; - gate_out_1.pull = DSY_GPIO_NOPULL; - gate_out_1.pin = B5; - dsy_gpio_init(&gate_out_1); - - gate_out_2.mode = DSY_GPIO_MODE_OUTPUT_PP; - gate_out_2.pull = DSY_GPIO_NOPULL; - gate_out_2.pin = B6; - dsy_gpio_init(&gate_out_2); + gate_out_1.Init(B5, GPIO::Mode::OUTPUT); + gate_out_2.Init(B6, GPIO::Mode::OUTPUT); /** DAC init */ pimpl_->InitDac(); @@ -464,7 +454,7 @@ namespace patch_sm pimpl_->WriteCvOut(channel, voltage); } - void DaisyPatchSM::SetLed(bool state) { dsy_gpio_write(&user_led, state); } + void DaisyPatchSM::SetLed(bool state) { user_led.Write(state); } bool DaisyPatchSM::ValidateSDRAM() { diff --git a/src/daisy_patch_sm.h b/src/daisy_patch_sm.h index 54e18df01..ee1986608 100644 --- a/src/daisy_patch_sm.h +++ b/src/daisy_patch_sm.h @@ -251,10 +251,10 @@ namespace patch_sm DacHandle dac; /** Dedicated Function Pins */ - dsy_gpio user_led; + GPIO user_led; AnalogControl controls[ADC_LAST]; GateIn gate_in_1, gate_in_2; - dsy_gpio gate_out_1, gate_out_2; + GPIO gate_out_1, gate_out_2; /** Pin Accessors for the DaisyPatchSM hardware From 4f9d07a3249aa633dcbf8462dbb899bcaf1080f1 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 19:23:54 -0400 Subject: [PATCH 04/38] Update DaisyField to use GPIO --- src/daisy_field.cpp | 5 +---- src/daisy_field.h | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/daisy_field.cpp b/src/daisy_field.cpp index f5c851528..747ff3ec4 100644 --- a/src/daisy_field.cpp +++ b/src/daisy_field.cpp @@ -142,10 +142,7 @@ void DaisyField::Init(bool boost) // Gate In gate_in.Init(PIN_GATE_IN); // Gate Out - gate_out.mode = DSY_GPIO_MODE_OUTPUT_PP; - gate_out.pull = DSY_GPIO_NOPULL; - gate_out.pin = PIN_GATE_OUT; - dsy_gpio_init(&gate_out); + gate_out.Init(PIN_GATE_OUT, GPIO::Mode::OUTPUT); //midi MidiUartHandler::Config midi_config; diff --git a/src/daisy_field.h b/src/daisy_field.h index c31ef368d..574270541 100644 --- a/src/daisy_field.h +++ b/src/daisy_field.h @@ -212,7 +212,7 @@ class DaisyField DaisySeed seed; OledDisplay display; - dsy_gpio gate_out; + GPIO gate_out; GateIn gate_in; LedDriverPca9685<2, true> led_driver; Switch sw[SW_LAST]; From 62796432ec51b25bdc68b8fc1ed017d2974ec772 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 19:39:17 -0400 Subject: [PATCH 05/38] Update LED and RGBLed to use GPIO and Pin --- src/hid/led.cpp | 8 +++----- src/hid/led.h | 4 ++-- src/hid/rgb_led.cpp | 6 +++--- src/hid/rgb_led.h | 3 +-- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/hid/led.cpp b/src/hid/led.cpp index 1733f7875..68f94a9c9 100644 --- a/src/hid/led.cpp +++ b/src/hid/led.cpp @@ -5,13 +5,11 @@ using namespace daisy; #define RESOLUTION_MAX (65535) -void Led::Init(dsy_gpio_pin pin, bool invert, float samplerate) +void Led::Init(Pin pin, bool invert, float samplerate) { // Init hardware LED // Simple OUTPUT GPIO for now. - hw_pin_.pin = pin; - hw_pin_.mode = DSY_GPIO_MODE_OUTPUT_PP; - dsy_gpio_init(&hw_pin_); + hw_pin_.Init(pin, GPIO::Mode::OUTPUT); // Set internal stuff. bright_ = 0.0f; pwm_cnt_ = 0; @@ -41,7 +39,7 @@ void Led::Update() pwm_ += 120.f / samplerate_; if(pwm_ > 1.f) pwm_ -= 1.f; - dsy_gpio_write(&hw_pin_, bright_ > pwm_ ? on_ : off_); + hw_pin_.Write(bright_ > pwm_ ? on_ : off_); // Once we have a slower timer set up: // Right now its too fast. diff --git a/src/hid/led.h b/src/hid/led.h index e4f38aa66..b34597726 100644 --- a/src/hid/led.h +++ b/src/hid/led.h @@ -30,7 +30,7 @@ class Led \param invert will set whether to internally invert the brightness due to hardware config. \param samplerate sets the rate at which 'Update()' will be called (used for software PWM) */ - void Init(dsy_gpio_pin pin, bool invert, float samplerate = 1000.0f); + void Init(Pin pin, bool invert, float samplerate = 1000.0f); /** Sets the brightness of the Led. @@ -56,7 +56,7 @@ class Led float pwm_; float samplerate_; bool invert_, on_, off_; - dsy_gpio hw_pin_; + GPIO hw_pin_; }; } // namespace daisy diff --git a/src/hid/rgb_led.cpp b/src/hid/rgb_led.cpp index 3226268af..32a642fcc 100644 --- a/src/hid/rgb_led.cpp +++ b/src/hid/rgb_led.cpp @@ -1,8 +1,8 @@ #include "hid/rgb_led.h" using namespace daisy; -void RgbLed::Init(dsy_gpio_pin red, - dsy_gpio_pin green, - dsy_gpio_pin blue, +void RgbLed::Init(Pin red, + Pin green, + Pin blue, bool invert) { r_.Init(red, invert); diff --git a/src/hid/rgb_led.h b/src/hid/rgb_led.h index 382df448f..a3e01974d 100644 --- a/src/hid/rgb_led.h +++ b/src/hid/rgb_led.h @@ -23,8 +23,7 @@ class RgbLed \param blue Blue element \param invert Flips led polarity */ - void - Init(dsy_gpio_pin red, dsy_gpio_pin green, dsy_gpio_pin blue, bool invert); + void Init(Pin red, Pin green, Pin blue, bool invert); /** Sets each element of the LED with a floating point number 0-1 \param r Red element From 4e42d1ccdc54dc73df7a0b2e4a263ed1ee92fcae Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 20:03:10 -0400 Subject: [PATCH 06/38] Update AK4556 CODEC to use GPIO and Pin This also finally switches the AK4556 CODEC from a static set of functions to instance variables. This is required due to how GPIO instances update their internal port_base_addr_ on Init(), which is then later required for DeInit(). --- src/daisy.h | 1 + src/daisy_patch.cpp | 4 +--- src/daisy_patch.h | 1 + src/daisy_seed.cpp | 7 +------ src/daisy_seed.h | 1 + src/dev/codec_ak4556.cpp | 20 +++++++------------- src/dev/codec_ak4556.h | 11 +++++------ 7 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/daisy.h b/src/daisy.h index 88a26795c..c629ba8b3 100644 --- a/src/daisy.h +++ b/src/daisy.h @@ -43,6 +43,7 @@ #include "hid/rgb_led.h" #include "dev/sr_595.h" #include "dev/apds9960.h" +#include "dev/codec_ak4556.h" #include "dev/codec_pcm3060.h" #include "dev/codec_wm8731.h" #include "dev/dps310.h" diff --git a/src/daisy_patch.cpp b/src/daisy_patch.cpp index cf430575e..172631520 100644 --- a/src/daisy_patch.cpp +++ b/src/daisy_patch.cpp @@ -1,5 +1,4 @@ #include "daisy_patch.h" -#include "dev/codec_ak4556.h" using namespace daisy; @@ -216,8 +215,7 @@ void DaisyPatch::InitAudio() // Reset Pin for AK4556 // Built-in AK4556 was reset during Seed Init - dsy_gpio_pin codec_reset_pin = PIN_AK4556_RESET; - Ak4556::Init(codec_reset_pin); + codec.Init(PIN_AK4556_RESET); // Reinit Audio for _both_ codecs... AudioHandle::Config cfg; diff --git a/src/daisy_patch.h b/src/daisy_patch.h index 4988040d6..15d966775 100644 --- a/src/daisy_patch.h +++ b/src/daisy_patch.h @@ -115,6 +115,7 @@ class DaisyPatch Helper functions above provide easier access to much of what they are capable of. */ DaisySeed seed; /**< Seed object */ + Ak4556 codec; /**< Patch's second CODEC */ Encoder encoder; /**< Encoder object */ AnalogControl controls[CTRL_LAST]; /**< Array of controls*/ GateIn gate_input[GATE_IN_LAST]; /**< Gate inputs */ diff --git a/src/daisy_seed.cpp b/src/daisy_seed.cpp index fbc7a0200..10667b04b 100644 --- a/src/daisy_seed.cpp +++ b/src/daisy_seed.cpp @@ -1,10 +1,5 @@ #include "daisy_seed.h" -extern "C" -{ -#include "dev/codec_ak4556.h" -} - using namespace daisy; constexpr GPIOPort SEED_LED_PORT = PORTC; @@ -320,7 +315,7 @@ void DaisySeed::ConfigureAudio() sai_config.pin_config.sb = Pin(PORTE, 3); constexpr Pin codec_reset_pin = Pin(PORTB, 11); - Ak4556::Init(codec_reset_pin); + codec.Init(codec_reset_pin); } break; } diff --git a/src/daisy_seed.h b/src/daisy_seed.h index 95ec8b771..86b72a14f 100644 --- a/src/daisy_seed.h +++ b/src/daisy_seed.h @@ -147,6 +147,7 @@ class DaisySeed UsbHandle usb_handle; /**< & */ GPIO led, testpoint; System system; + Ak4556 codec; /** Internal indices for DaisySeed-equivalent devices * This shouldn't have any effect on user-facing code, diff --git a/src/dev/codec_ak4556.cpp b/src/dev/codec_ak4556.cpp index 7df1af035..8327af366 100644 --- a/src/dev/codec_ak4556.cpp +++ b/src/dev/codec_ak4556.cpp @@ -4,25 +4,19 @@ namespace daisy { -void Ak4556::Init(dsy_gpio_pin reset_pin) +void Ak4556::Init(Pin reset_pin) { - dsy_gpio reset; - reset.pin = reset_pin; - reset.mode = DSY_GPIO_MODE_OUTPUT_PP; - reset.pull = DSY_GPIO_NOPULL; - dsy_gpio_init(&reset); - dsy_gpio_write(&reset, 1); + reset_.Init(reset_pin, GPIO::Mode::OUTPUT); + reset_.Write(1); System::Delay(1); - dsy_gpio_write(&reset, 0); + reset_.Write(0); System::Delay(1); - dsy_gpio_write(&reset, 1); + reset_.Write(1); } -void Ak4556::DeInit(dsy_gpio_pin reset_pin) +void Ak4556::DeInit() { - dsy_gpio reset; - reset.pin = reset_pin; - dsy_gpio_deinit(&reset); + reset_.DeInit(); } diff --git a/src/dev/codec_ak4556.h b/src/dev/codec_ak4556.h index 612391b5e..fcd86f128 100644 --- a/src/dev/codec_ak4556.h +++ b/src/dev/codec_ak4556.h @@ -3,6 +3,7 @@ #define DSY_CODEC_AK4556_H #include "daisy_core.h" +#include "per/gpio.h" namespace daisy { @@ -20,16 +21,14 @@ class Ak4556 ~Ak4556() {} /** Initialization function for Ak4556 - ** Can be called statically: - ** Ak4556::Init(pin); ** */ - static void Init(dsy_gpio_pin reset_pin); + void Init(Pin reset_pin); /** Deinitialization function for Ak4556 - ** Can be called statically: - ** Ak4556::DeInit(pin); ** */ - static void DeInit(dsy_gpio_pin reset_pin); + void DeInit(); + private: + GPIO reset_; }; } // namespace daisy From 48338165cdecd20905a4d713b39606b80ad56caf Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 20:11:43 -0400 Subject: [PATCH 07/38] Update HD44780 driver to use GPIO and Pin --- src/dev/lcd_hd44780.cpp | 51 +++++++++++------------------------------ src/dev/lcd_hd44780.h | 16 ++++++------- 2 files changed, 22 insertions(+), 45 deletions(-) diff --git a/src/dev/lcd_hd44780.cpp b/src/dev/lcd_hd44780.cpp index 5d09332d1..70720935d 100644 --- a/src/dev/lcd_hd44780.cpp +++ b/src/dev/lcd_hd44780.cpp @@ -32,9 +32,9 @@ Based on: HD44780-Stm32HAL by Olivier Van den Eede (https://github.com/4ilo/HD44 #define OPT_B 0x01 // Turn on cursor blink #define FUNCTION_SET 0x20 -#define OPT_DL 0x10 // Set interface data length -#define OPT_N 0x08 // Set number of display lines -#define OPT_F 0x04 // Set alternate font +#define OPT_DL 0x10 // Set interface data length +#define OPT_N 0x08 // Set number of display lines +#define OPT_F 0x04 // Set alternate font #define SETCGRAM_ADDR 0x040 #define SET_DDRAM_ADDR 0x80 // Set DDRAM address @@ -51,36 +51,13 @@ namespace daisy void LcdHD44780::Init(const Config& config) { // init pins + lcd_pin_rs.Init(config.rs, GPIO::Mode::OUTPUT); + lcd_pin_en.Init(config.en, GPIO::Mode::OUTPUT); - lcd_pin_rs.pin = config.rs; - lcd_pin_rs.mode = DSY_GPIO_MODE_OUTPUT_PP; - lcd_pin_rs.pull = DSY_GPIO_NOPULL; - dsy_gpio_init(&lcd_pin_rs); - - lcd_pin_en.pin = config.en; - lcd_pin_en.mode = DSY_GPIO_MODE_OUTPUT_PP; - lcd_pin_en.pull = DSY_GPIO_NOPULL; - dsy_gpio_init(&lcd_pin_en); - - lcd_data_pin[0].pin = config.d4; - lcd_data_pin[0].mode = DSY_GPIO_MODE_OUTPUT_PP; - lcd_data_pin[0].pull = DSY_GPIO_NOPULL; - dsy_gpio_init(&lcd_data_pin[0]); - - lcd_data_pin[1].pin = config.d5; - lcd_data_pin[1].mode = DSY_GPIO_MODE_OUTPUT_PP; - lcd_data_pin[1].pull = DSY_GPIO_NOPULL; - dsy_gpio_init(&lcd_data_pin[1]); - - lcd_data_pin[2].pin = config.d6; - lcd_data_pin[2].mode = DSY_GPIO_MODE_OUTPUT_PP; - lcd_data_pin[2].pull = DSY_GPIO_NOPULL; - dsy_gpio_init(&lcd_data_pin[2]); - - lcd_data_pin[3].pin = config.d7; - lcd_data_pin[3].mode = DSY_GPIO_MODE_OUTPUT_PP; - lcd_data_pin[3].pull = DSY_GPIO_NOPULL; - dsy_gpio_init(&lcd_data_pin[3]); + lcd_data_pin[0].Init(config.d4, GPIO::Mode::OUTPUT); + lcd_data_pin[1].Init(config.d5, GPIO::Mode::OUTPUT); + lcd_data_pin[2].Init(config.d6, GPIO::Mode::OUTPUT); + lcd_data_pin[3].Init(config.d7, GPIO::Mode::OUTPUT); cursor_on = config.cursor_on; cursor_blink = config.cursor_blink; @@ -150,7 +127,7 @@ void LcdHD44780::Clear() void LcdHD44780::WriteCommand(uint8_t command) { - dsy_gpio_write(&lcd_pin_rs, LCD_COMMAND_REG); + lcd_pin_rs.Write(LCD_COMMAND_REG); Write((command >> 4), LCD_NIB); Write(command & 0x0F, LCD_NIB); @@ -161,7 +138,7 @@ void LcdHD44780::WriteCommand(uint8_t command) void LcdHD44780::WriteData(uint8_t data) { - dsy_gpio_write(&lcd_pin_rs, LCD_DATA_REG); + lcd_pin_rs.Write(LCD_DATA_REG); Write(data >> 4, LCD_NIB); Write(data & 0x0F, LCD_NIB); @@ -174,14 +151,14 @@ void LcdHD44780::Write(uint8_t data, uint8_t len) { for(uint8_t i = 0; i < len; i++) { - dsy_gpio_write(&lcd_data_pin[i], (data >> i) & 0x01); + lcd_data_pin[i].Write((data >> i) & 0x01); } // toggle - dsy_gpio_write(&lcd_pin_en, 1); + lcd_pin_en.Write(1); System::Delay(1); - dsy_gpio_write(&lcd_pin_en, 0); + lcd_pin_en.Write(0); } } // namespace daisy diff --git a/src/dev/lcd_hd44780.h b/src/dev/lcd_hd44780.h index 8261bd6b7..e17e5e267 100644 --- a/src/dev/lcd_hd44780.h +++ b/src/dev/lcd_hd44780.h @@ -24,9 +24,9 @@ class LcdHD44780 struct Config { - bool cursor_on; - bool cursor_blink; - dsy_gpio_pin rs, en, d4, d5, d6, d7; + bool cursor_on; + bool cursor_blink; + Pin rs, en, d4, d5, d6, d7; }; /** @@ -60,11 +60,11 @@ class LcdHD44780 void Clear(); private: - bool cursor_on; - bool cursor_blink; - dsy_gpio lcd_pin_rs; - dsy_gpio lcd_pin_en; - dsy_gpio lcd_data_pin[4]; // D4-D7 + bool cursor_on; + bool cursor_blink; + GPIO lcd_pin_rs; + GPIO lcd_pin_en; + GPIO lcd_data_pin[4]; // D4-D7 void WriteData(uint8_t); void WriteCommand(uint8_t); From c83c10c2517ae9811b40cf48ead067ff0e4603ec Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 20:14:45 -0400 Subject: [PATCH 08/38] Update PCA9685 driver to use GPIO and Pin --- src/dev/leddriver.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/dev/leddriver.h b/src/dev/leddriver.h index 6c2b99ef0..8dbd7129d 100644 --- a/src/dev/leddriver.h +++ b/src/dev/leddriver.h @@ -66,7 +66,7 @@ class LedDriverPca9685 const uint8_t (&addresses)[numDrivers], DmaBuffer dma_buffer_a, DmaBuffer dma_buffer_b, - dsy_gpio_pin oe_pin = {DSY_GPIOX, 0}) + Pin oe_pin = Pin(PORTX, 0)) { i2c_ = i2c; draw_buffer_ = dma_buffer_a; @@ -218,13 +218,10 @@ class LedDriverPca9685 void InitializeDrivers() { // init OE pin and pull low to enable outputs - if(oe_pin_.port != DSY_GPIOX) + if(oe_pin_.port != PORTX) { - oe_pin_gpio_.pin = oe_pin_; - oe_pin_gpio_.mode = DSY_GPIO_MODE_OUTPUT_PP; - oe_pin_gpio_.pull = DSY_GPIO_NOPULL; - dsy_gpio_init(&oe_pin_gpio_); - dsy_gpio_write(&oe_pin_gpio_, 0); + oe_pin_gpio_.Init(oe_pin_, GPIO::Mode::OUTPUT); + oe_pin_gpio_.Write(0); } // init the individual drivers @@ -275,8 +272,8 @@ class LedDriverPca9685 PCA9685TransmitBuffer* draw_buffer_; PCA9685TransmitBuffer* transmit_buffer_; uint8_t addresses_[numDrivers]; - dsy_gpio_pin oe_pin_; - dsy_gpio oe_pin_gpio_; + Pin oe_pin_; + GPIO oe_pin_gpio_; // index of the dirver that is currently updated. volatile int8_t current_driver_idx_; const uint16_t gamma_table_[256] = { From 5035b7123702ec850bdb2cef22ce671fd79177be Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 20:27:04 -0400 Subject: [PATCH 09/38] Update SSD130X driver to use GPIO and Pin --- src/dev/oled_ssd130x.h | 104 ++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 58 deletions(-) diff --git a/src/dev/oled_ssd130x.h b/src/dev/oled_ssd130x.h index 965b1f0c7..6a4f52cb4 100644 --- a/src/dev/oled_ssd130x.h +++ b/src/dev/oled_ssd130x.h @@ -29,8 +29,8 @@ class SSD130xI2CTransport i2c_config.periph = I2CHandle::Config::Peripheral::I2C_1; i2c_config.speed = I2CHandle::Config::Speed::I2C_1MHZ; i2c_config.mode = I2CHandle::Config::Mode::I2C_MASTER; - i2c_config.pin_config.scl = {DSY_GPIOB, 8}; - i2c_config.pin_config.sda = {DSY_GPIOB, 9}; + i2c_config.pin_config.scl = Pin(PORTB, 8); + i2c_config.pin_config.sda = Pin(PORTB, 9); i2c_address = 0x3C; } }; @@ -75,8 +75,8 @@ class SSD130x4WireSpiTransport SpiHandle::Config spi_config; struct { - dsy_gpio_pin dc; /**< & */ - dsy_gpio_pin reset; /**< & */ + Pin dc; /**< & */ + Pin reset; /**< & */ } pin_config; void Defaults() { @@ -91,50 +91,46 @@ class SSD130x4WireSpiTransport spi_config.nss = SpiHandle::Config::NSS::HARD_OUTPUT; spi_config.baud_prescaler = SpiHandle::Config::BaudPrescaler::PS_8; // SPI pin config - spi_config.pin_config.sclk = {DSY_GPIOG, 11}; - spi_config.pin_config.miso = {DSY_GPIOX, 0}; - spi_config.pin_config.mosi = {DSY_GPIOB, 5}; - spi_config.pin_config.nss = {DSY_GPIOG, 10}; + spi_config.pin_config.sclk = Pin(PORTG, 11); + spi_config.pin_config.miso = Pin(PORTX, 0); + spi_config.pin_config.mosi = Pin(PORTB, 5); + spi_config.pin_config.nss = Pin(PORTG, 10); // SSD130x control pin config - pin_config.dc = {DSY_GPIOB, 4}; - pin_config.reset = {DSY_GPIOB, 15}; + pin_config.dc = Pin(PORTB, 4); + pin_config.reset = Pin(PORTB, 15); } }; void Init(const Config& config) { // Initialize both GPIO - pin_dc_.mode = DSY_GPIO_MODE_OUTPUT_PP; - pin_dc_.pin = config.pin_config.dc; - dsy_gpio_init(&pin_dc_); - pin_reset_.mode = DSY_GPIO_MODE_OUTPUT_PP; - pin_reset_.pin = config.pin_config.reset; - dsy_gpio_init(&pin_reset_); + pin_dc_.Init(config.pin_config.dc, GPIO::Mode::OUTPUT); + pin_reset_.Init(config.pin_config.reset, GPIO::Mode::OUTPUT); // Initialize SPI spi_.Init(config.spi_config); // Reset and Configure OLED. - dsy_gpio_write(&pin_reset_, 0); + pin_reset_.Write(0); System::Delay(10); - dsy_gpio_write(&pin_reset_, 1); + pin_reset_.Write(1); System::Delay(10); }; void SendCommand(uint8_t cmd) { - dsy_gpio_write(&pin_dc_, 0); + pin_dc_.Write(0); spi_.BlockingTransmit(&cmd, 1); }; void SendData(uint8_t* buff, size_t size) { - dsy_gpio_write(&pin_dc_, 1); + pin_dc_.Write(1); spi_.BlockingTransmit(buff, size); }; private: SpiHandle spi_; - dsy_gpio pin_reset_; - dsy_gpio pin_dc_; + GPIO pin_reset_; + GPIO pin_dc_; }; /** @@ -152,58 +148,50 @@ class SSD130x4WireSoftSpiTransport } struct { - uint32_t sclk_delay; - dsy_gpio_pin sclk; - dsy_gpio_pin mosi; - dsy_gpio_pin dc; - dsy_gpio_pin reset; + uint32_t sclk_delay; + Pin sclk; + Pin mosi; + Pin dc; + Pin reset; } pin_config; void Defaults() { pin_config.sclk_delay = 0; // fast as possible?! // SPI peripheral config - pin_config.sclk = {DSY_GPIOD, 3}; /**< D10 - SPI2 SCK */ - pin_config.mosi = {DSY_GPIOC, 3}; /**< D9 - SPI2 MOSI */ + pin_config.sclk = Pin(PORTD, 3); /**< D10 - SPI2 SCK */ + pin_config.mosi = Pin(PORTC, 3); /**< D9 - SPI2 MOSI */ // SSD130x control pin config - pin_config.dc = {DSY_GPIOC, 11}; //D2 - pin_config.reset = {DSY_GPIOC, 10}; //D3 + pin_config.dc = Pin(PORTC, 11); //D2 + pin_config.reset = Pin(PORTC, 10); //D3 } }; void Init(const Config& config) { // Initialize both GPIO - pin_sclk_.mode = DSY_GPIO_MODE_OUTPUT_PP; - pin_sclk_.pin = config.pin_config.sclk; - dsy_gpio_init(&pin_sclk_); - dsy_gpio_write(&pin_sclk_, 1); //ClockPolarity::LOW - clk_delay = config.pin_config.sclk_delay; - pin_mosi_.mode = DSY_GPIO_MODE_OUTPUT_PP; - pin_mosi_.pin = config.pin_config.mosi; - dsy_gpio_init(&pin_mosi_); - dsy_gpio_write(&pin_mosi_, 0); - - pin_dc_.mode = DSY_GPIO_MODE_OUTPUT_PP; - pin_dc_.pin = config.pin_config.dc; - dsy_gpio_init(&pin_dc_); - pin_reset_.mode = DSY_GPIO_MODE_OUTPUT_PP; - pin_reset_.pin = config.pin_config.reset; - dsy_gpio_init(&pin_reset_); + pin_sclk_.Init(config.pin_config.sclk, GPIO::Mode::OUTPUT); + pin_sclk_.Write(1); //ClockPolarity::LOW + clk_delay = config.pin_config.sclk_delay; + pin_mosi_.Init(config.pin_config.mosi, GPIO::Mode::OUTPUT); + pin_mosi_.Write(0); + + pin_dc_.Init(config.pin_config.dc, GPIO::Mode::OUTPUT); + pin_reset_.Init(config.pin_config.reset, GPIO::Mode::OUTPUT); // Reset and Configure OLED. - dsy_gpio_write(&pin_reset_, 0); + pin_reset_.Write(0); System::Delay(10); - dsy_gpio_write(&pin_reset_, 1); + pin_reset_.Write(1); System::Delay(10); }; void SendCommand(uint8_t cmd) { - dsy_gpio_write(&pin_dc_, 0); + pin_dc_.Write(0); SoftSpiTransmit(cmd); }; void SendData(uint8_t* buff, size_t size) { - dsy_gpio_write(&pin_dc_, 1); + pin_dc_.Write(1); for(size_t i = 0; i < size; i++) SoftSpiTransmit(buff[i]); }; @@ -218,23 +206,23 @@ class SSD130x4WireSoftSpiTransport for(uint8_t bit = 0u; bit < 8u; bit++) { - dsy_gpio_write(&pin_mosi_, ((val & (1 << bit)) ? 1 : 0)); + pin_mosi_.Write((val & (1 << bit)) ? 1 : 0); System::DelayTicks(clk_delay); - dsy_gpio_toggle(&pin_sclk_); + pin_sclk_.Toggle(); System::DelayTicks(clk_delay); - dsy_gpio_toggle(&pin_sclk_); + pin_sclk_.Toggle(); } } uint32_t clk_delay; - dsy_gpio pin_sclk_; - dsy_gpio pin_mosi_; - dsy_gpio pin_reset_; - dsy_gpio pin_dc_; + GPIO pin_sclk_; + GPIO pin_mosi_; + GPIO pin_reset_; + GPIO pin_dc_; }; From afb38c9296ede4b0cf7c684ca33f974243b59cec Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 20:39:41 -0400 Subject: [PATCH 10/38] Move SR595 Driver into daisy namespace --- src/dev/sr_595.cpp | 4 ++++ src/dev/sr_595.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/dev/sr_595.cpp b/src/dev/sr_595.cpp index c507251f7..c3800610e 100644 --- a/src/dev/sr_595.cpp +++ b/src/dev/sr_595.cpp @@ -1,5 +1,7 @@ #include #include "dev/sr_595.h" +namespace daisy +{ void ShiftRegister595::Init(dsy_gpio_pin *pin_cfg, size_t num_daisy_chained) { // Initialize Pins as outputs @@ -41,3 +43,5 @@ void ShiftRegister595::Write() } dsy_gpio_write(&pin_[PIN_LATCH], 1); } + +} // namespace daisy \ No newline at end of file diff --git a/src/dev/sr_595.h b/src/dev/sr_595.h index 6c2f666c7..9d6a9febf 100644 --- a/src/dev/sr_595.h +++ b/src/dev/sr_595.h @@ -5,6 +5,8 @@ #include "daisy_core.h" #include "per/gpio.h" +namespace daisy +{ const size_t kMaxSr595DaisyChain = 16; /**< Maximum Number of chained devices Connect device's QH' pin to the next chips serial input*/ @@ -56,6 +58,7 @@ class ShiftRegister595 uint8_t state_[kMaxSr595DaisyChain]; size_t num_devices_; }; +} // namespace daisy #endif /** @} */ From 95319e30379525458d8b8d0f345d3b5a7616f1b9 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 20:40:33 -0400 Subject: [PATCH 11/38] Update SR595 driver to use GPIO and Pin --- src/dev/sr_595.cpp | 20 ++++++++------------ src/dev/sr_595.h | 9 +++++---- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/dev/sr_595.cpp b/src/dev/sr_595.cpp index c3800610e..613290399 100644 --- a/src/dev/sr_595.cpp +++ b/src/dev/sr_595.cpp @@ -2,15 +2,12 @@ #include "dev/sr_595.h" namespace daisy { -void ShiftRegister595::Init(dsy_gpio_pin *pin_cfg, size_t num_daisy_chained) +void ShiftRegister595::Init(Pin *pin_cfg, size_t num_daisy_chained) { // Initialize Pins as outputs for(size_t i = 0; i < NUM_PINS; i++) { - pin_[i].pin = pin_cfg[i]; - pin_[i].mode = DSY_GPIO_MODE_OUTPUT_PP; - pin_[i].pull = DSY_GPIO_NOPULL; - dsy_gpio_init(&pin_[i]); + pin_[i].Init(pin_cfg[i], GPIO::Mode::OUTPUT); } std::fill(state_, state_ + kMaxSr595DaisyChain, 0x00); num_devices_ = num_daisy_chained; @@ -32,16 +29,15 @@ void ShiftRegister595::Write() { // This is about 2MHz clock speeds without delays // Max Freq is 4-6 MHz at 2V, and 21-31MHz at 4V5. - dsy_gpio_write(&pin_[PIN_LATCH], 0); + pin_[PIN_LATCH].Write(0); for(size_t i = 0; i < num_devices_ * 8; i++) { - dsy_gpio_write(&pin_[PIN_CLK], 0); - dsy_gpio_write(&pin_[PIN_DATA], - state_[((num_devices_ - 1) - (i / 8))] - & (1 << (7 - (i % 8)))); - dsy_gpio_write(&pin_[PIN_CLK], 1); + pin_[PIN_CLK].Write(0); + pin_[PIN_DATA].Write(state_[((num_devices_ - 1) - (i / 8))] + & (1 << (7 - (i % 8)))); + pin_[PIN_CLK].Write(1); } - dsy_gpio_write(&pin_[PIN_LATCH], 1); + pin_[PIN_LATCH].Write(1); } } // namespace daisy \ No newline at end of file diff --git a/src/dev/sr_595.h b/src/dev/sr_595.h index 9d6a9febf..81cd9ec6f 100644 --- a/src/dev/sr_595.h +++ b/src/dev/sr_595.h @@ -25,6 +25,7 @@ class ShiftRegister595 public: /** The following pins correspond to the hardware connections to the 595. + \note TODO: This should probably be switched to using a pin config structure similar to other drivers */ enum Pins { @@ -41,7 +42,7 @@ class ShiftRegister595 * \param pin_cfg is an array of dsy_gpio_pin corresponding the the Pins enum above. * \param num_daisy_chained (default = 1) is the number of 595 devices daisy chained together. */ - void Init(dsy_gpio_pin *pin_cfg, size_t num_daisy_chained = 1); + void Init(Pin *pin_cfg, size_t num_daisy_chained = 1); /** Sets the state of the specified output. \param idx The index starts with QA on the first device and ends with QH on the last device. @@ -54,9 +55,9 @@ class ShiftRegister595 void Write(); private: - dsy_gpio pin_[NUM_PINS]; - uint8_t state_[kMaxSr595DaisyChain]; - size_t num_devices_; + GPIO pin_[NUM_PINS]; + uint8_t state_[kMaxSr595DaisyChain]; + size_t num_devices_; }; } // namespace daisy From dc614a2f1ac3d0aec1b15704b7bd149fdb9b6924 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 20:48:45 -0400 Subject: [PATCH 12/38] Update 4021 driver with GPIO and Pin --- src/dev/sr_4021.h | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/src/dev/sr_4021.h b/src/dev/sr_4021.h index 9ccbca027..881cb8a95 100644 --- a/src/dev/sr_4021.h +++ b/src/dev/sr_4021.h @@ -40,9 +40,9 @@ class ShiftRegister4021 /** Configuration Structure for handling the pin setting of the device */ struct Config { - dsy_gpio_pin clk; /**< Clock pin to attach to pin 10 of device(s) */ - dsy_gpio_pin latch; /**< Latch pin to attach to pin 9 of device(s) */ - dsy_gpio_pin data[num_parallel]; /**< Data Pin(s) */ + Pin clk; /**< Clock pin to attach to pin 10 of device(s) */ + Pin latch; /**< Latch pin to attach to pin 9 of device(s) */ + Pin data[num_parallel]; /**< Data Pin(s) */ }; ShiftRegister4021() {} @@ -53,20 +53,11 @@ class ShiftRegister4021 { config_ = cfg; // Init GPIO - clk_.mode = DSY_GPIO_MODE_OUTPUT_PP; - clk_.pull = DSY_GPIO_NOPULL; - clk_.pin = cfg.clk; - dsy_gpio_init(&clk_); - latch_.mode = DSY_GPIO_MODE_OUTPUT_PP; - latch_.pull = DSY_GPIO_NOPULL; - latch_.pin = cfg.latch; - dsy_gpio_init(&latch_); + clk_.Init(cfg.clk, GPIO::Mode::OUTPUT); + latch_.Init(cfg.latch, GPIO::Mode::OUTPUT); for(size_t i = 0; i < num_parallel; i++) { - data_[i].mode = DSY_GPIO_MODE_INPUT; - data_[i].pull = DSY_GPIO_NOPULL; - data_[i].pin = cfg.data[i]; - dsy_gpio_init(&data_[i]); + data_[i].Init(cfg.data[i], GPIO::Mode::INPUT); } // Init States for(size_t i = 0; i < kTotalStates; i++) @@ -78,22 +69,22 @@ class ShiftRegister4021 /** Reads the states of all pins on the connected device(s) */ void Update() { - dsy_gpio_write(&clk_, 0); - dsy_gpio_write(&latch_, 1); + clk_.Write(0); + latch_.Write(1); System::DelayTicks(1); - dsy_gpio_write(&latch_, 0); + latch_.Write(0); uint32_t idx; for(size_t i = 0; i < 8 * num_daisychained; i++) { - dsy_gpio_write(&clk_, 0); + clk_.Write(0); System::DelayTicks(1); for(size_t j = 0; j < num_parallel; j++) { idx = (8 * num_daisychained - 1) - i; idx += (8 * num_daisychained * j); - states_[idx] = dsy_gpio_read(&data_[j]); + states_[idx] = data_[j].Read(); } - dsy_gpio_write(&clk_, 1); + clk_.Write(1); System::DelayTicks(1); } } @@ -112,9 +103,9 @@ class ShiftRegister4021 static constexpr int kTotalStates = 8 * num_daisychained * num_parallel; Config config_; bool states_[kTotalStates]; - dsy_gpio clk_; - dsy_gpio latch_; - dsy_gpio data_[num_parallel]; + GPIO clk_; + GPIO latch_; + GPIO data_[num_parallel]; }; } // namespace daisy From e1d6ce259493738fb1a8d1f6a8206dacd71fa895 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 20:53:21 -0400 Subject: [PATCH 13/38] Update Encoder to use GPIO and Pin --- src/hid/encoder.cpp | 19 +++++-------------- src/hid/encoder.h | 7 ++----- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/hid/encoder.cpp b/src/hid/encoder.cpp index ceec8bba0..a6064a6e3 100644 --- a/src/hid/encoder.cpp +++ b/src/hid/encoder.cpp @@ -2,23 +2,14 @@ using namespace daisy; -void Encoder::Init(dsy_gpio_pin a, - dsy_gpio_pin b, - dsy_gpio_pin click, - float update_rate) +void Encoder::Init(Pin a, Pin b, Pin click, float update_rate) { last_update_ = System::GetNow(); updated_ = false; // Init GPIO for A, and B - hw_a_.pin = a; - hw_a_.mode = DSY_GPIO_MODE_INPUT; - hw_a_.pull = DSY_GPIO_PULLUP; - hw_b_.pin = b; - hw_b_.mode = DSY_GPIO_MODE_INPUT; - hw_b_.pull = DSY_GPIO_PULLUP; - dsy_gpio_init(&hw_a_); - dsy_gpio_init(&hw_b_); + hw_a_.Init(a, GPIO::Mode::INPUT, GPIO::Pull::PULLUP); + hw_b_.Init(b, GPIO::Mode::INPUT, GPIO::Pull::PULLUP); // Default Initialization for Switch sw_.Init(click); // Set initial states, etc. @@ -38,8 +29,8 @@ void Encoder::Debounce() updated_ = true; // Shift Button states to debounce - a_ = (a_ << 1) | dsy_gpio_read(&hw_a_); - b_ = (b_ << 1) | dsy_gpio_read(&hw_b_); + a_ = (a_ << 1) | hw_a_.Read(); + b_ = (b_ << 1) | hw_b_.Read(); // infer increment direction inc_ = 0; // reset inc_ first diff --git a/src/hid/encoder.h b/src/hid/encoder.h index e2e7601b2..6d89a635c 100644 --- a/src/hid/encoder.h +++ b/src/hid/encoder.h @@ -23,10 +23,7 @@ class Encoder /** Initializes the encoder with the specified hardware pins. * Update rate is to be deprecated in a future release */ - void Init(dsy_gpio_pin a, - dsy_gpio_pin b, - dsy_gpio_pin click, - float update_rate = 0.f); + void Init(Pin a, Pin b, Pin click, float update_rate = 0.f); /** Called at update_rate to debounce and handle timing for the switch. * In order for events not to be missed, its important that the Edge/Pressed checks be made at the same rate as the debounce function is being called. */ @@ -56,7 +53,7 @@ class Encoder uint32_t last_update_; bool updated_; Switch sw_; - dsy_gpio hw_a_, hw_b_; + GPIO hw_a_, hw_b_; uint8_t a_, b_; int32_t inc_; }; From ee05043f0ba6e18f944e33ec5aa0ce76a4b6fb74 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 21:01:50 -0400 Subject: [PATCH 14/38] Update Switch driver to use GPIO and Pin Also migrates from internal custom Pull representation to the global GPIO::Pull --- src/hid/switch.cpp | 36 +++++++++++++++--------------------- src/hid/switch.h | 20 ++++++-------------- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/src/hid/switch.cpp b/src/hid/switch.cpp index 56dbce7e5..6553edaa7 100644 --- a/src/hid/switch.cpp +++ b/src/hid/switch.cpp @@ -1,11 +1,11 @@ #include "hid/switch.h" using namespace daisy; -void Switch::Init(dsy_gpio_pin pin, - float update_rate, - Type t, - Polarity pol, - Pull pu) +void Switch::Init(Pin pin, + float update_rate, + Type t, + Polarity pol, + GPIO::Pull pu) { last_update_ = System::GetNow(); updated_ = false; @@ -13,21 +13,16 @@ void Switch::Init(dsy_gpio_pin pin, t_ = t; // Flip may seem opposite to logical direction, // but here 1 is pressed, 0 is not. - flip_ = pol == POLARITY_INVERTED ? true : false; - hw_gpio_.pin = pin; - hw_gpio_.mode = DSY_GPIO_MODE_INPUT; - switch(pu) - { - case PULL_UP: hw_gpio_.pull = DSY_GPIO_PULLUP; break; - case PULL_DOWN: hw_gpio_.pull = DSY_GPIO_PULLDOWN; break; - case PULL_NONE: hw_gpio_.pull = DSY_GPIO_NOPULL; break; - default: hw_gpio_.pull = DSY_GPIO_PULLUP; break; - } - dsy_gpio_init(&hw_gpio_); + flip_ = pol == POLARITY_INVERTED ? true : false; + hw_gpio_.Init(pin, GPIO::Mode::INPUT, pu); } -void Switch::Init(dsy_gpio_pin pin, float update_rate) +void Switch::Init(Pin pin, float update_rate) { - Init(pin, update_rate, TYPE_MOMENTARY, POLARITY_INVERTED, PULL_UP); + Init(pin, + update_rate, + TYPE_MOMENTARY, + POLARITY_INVERTED, + GPIO::Pull::PULLUP); } void Switch::Debounce() @@ -42,9 +37,8 @@ void Switch::Debounce() updated_ = true; // shift over, and introduce new state. - state_ - = (state_ << 1) - | (flip_ ? !dsy_gpio_read(&hw_gpio_) : dsy_gpio_read(&hw_gpio_)); + const bool new_val = hw_gpio_.Read(); + state_ = (state_ << 1) | (flip_ ? !new_val : new_val); // Set time at which button was pressed if(state_ == 0x7f) rising_edge_time_ = System::GetNow(); diff --git a/src/hid/switch.h b/src/hid/switch.h index f6bc87509..1ea02d835 100644 --- a/src/hid/switch.h +++ b/src/hid/switch.h @@ -30,14 +30,6 @@ class Switch POLARITY_INVERTED, /**< & */ }; - /** Specifies whether to use built-in Pull Up/Down resistors to hold button at a given state when not engaged. */ - enum Pull - { - PULL_UP, /**< & */ - PULL_DOWN, /**< & */ - PULL_NONE, /**< & */ - }; - Switch() {} ~Switch() {} @@ -49,15 +41,14 @@ class Switch \param pol switch polarity -- Default: POLARITY_INVERTED \param pu switch pull up/down -- Default: PULL_UP */ - void - Init(dsy_gpio_pin pin, float update_rate, Type t, Polarity pol, Pull pu); + void Init(Pin pin, float update_rate, Type t, Polarity pol, GPIO::Pull pu = GPIO::Pull::PULLUP); /** Simplified Init. \param pin port/pin object to tell the switch which hardware pin to use. \param update_rate Left for backwards compatibility until next breaking change. */ - void Init(dsy_gpio_pin pin, float update_rate = 0.f); + void Init(Pin pin, float update_rate = 0.f); /** Called at update_rate to debounce and handle timing for the switch. @@ -80,8 +71,9 @@ class Switch /** \return true if the button is held down, without debouncing */ inline bool RawState() - { - return flip_ ? !dsy_gpio_read(&hw_gpio_) : dsy_gpio_read(&hw_gpio_); + { + const bool raw = hw_gpio_.Read(); + return flip_ ? !raw : raw; } /** \return the time in milliseconds that the button has been held (or toggle has been on) */ @@ -99,7 +91,7 @@ class Switch uint32_t last_update_; bool updated_; Type t_; - dsy_gpio hw_gpio_; + GPIO hw_gpio_; uint8_t state_; bool flip_; float rising_edge_time_; From a15d57dcfcd3823f4c2b84e79cdf6778e1df1226 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 21:05:06 -0400 Subject: [PATCH 15/38] Update Switch3 to use GPIO and Pin --- src/hid/switch3.h | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/hid/switch3.h b/src/hid/switch3.h index 3fc2678f3..42bb83b68 100644 --- a/src/hid/switch3.h +++ b/src/hid/switch3.h @@ -20,31 +20,24 @@ class Switch3 Switch3() {} ~Switch3() {} - void Init(dsy_gpio_pin pina, dsy_gpio_pin pinb) + void Init(Pin pina, Pin pinb) { - pina_gpio_.pin = pina; - pina_gpio_.mode = DSY_GPIO_MODE_INPUT; - pina_gpio_.pull = DSY_GPIO_PULLUP; - dsy_gpio_init(&pina_gpio_); - - pinb_gpio_.pin = pinb; - pinb_gpio_.mode = DSY_GPIO_MODE_INPUT; - pinb_gpio_.pull = DSY_GPIO_PULLUP; - dsy_gpio_init(&pinb_gpio_); + pina_gpio_.Init(pina, GPIO::Mode::INPUT, GPIO::Pull::PULLUP); + pinb_gpio_.Init(pinb, GPIO::Mode::INPUT, GPIO::Pull::PULLUP); } int Read() { - if(!dsy_gpio_read(&pina_gpio_)) + if(!pina_gpio_.Read()) return POS_UP; - if(!dsy_gpio_read(&pinb_gpio_)) + if(!pinb_gpio_.Read()) return POS_DOWN; return POS_CENTER; } private: - dsy_gpio pina_gpio_; - dsy_gpio pinb_gpio_; + GPIO pina_gpio_; + GPIO pinb_gpio_; }; } // namespace daisy From 1499c645826d63edb97471015644a3dd06cc0d84 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 21:33:09 -0400 Subject: [PATCH 16/38] Add Init() to GPIO for 0-parameter initialization --- src/per/gpio.cpp | 7 ++++++- src/per/gpio.h | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/per/gpio.cpp b/src/per/gpio.cpp index 4e35d35b3..f865259a6 100644 --- a/src/per/gpio.cpp +++ b/src/per/gpio.cpp @@ -8,6 +8,11 @@ void GPIO::Init(const Config &cfg) /** Copy Config */ cfg_ = cfg; + Init(); +} + +void GPIO::Init() +{ if(!cfg_.pin.IsValid()) return; @@ -142,7 +147,7 @@ extern "C" void dsy_gpio_init(const dsy_gpio *p) { - GPIO_TypeDef * port; + GPIO_TypeDef *port; GPIO_InitTypeDef ginit; switch(p->mode) { diff --git a/src/per/gpio.h b/src/per/gpio.h index e212681bb..0f31da3d9 100644 --- a/src/per/gpio.h +++ b/src/per/gpio.h @@ -73,6 +73,9 @@ class GPIO GPIO() {} + /** @brief Initialize the GPIO using the internal Config struct */ + void Init(); + /** @brief Initialize the GPIO from a Config struct * @param cfg reference to a Config struct populated with the desired settings */ From f8fbeb667d1a2409d163797e1b19617cc0b21cce Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 21:33:21 -0400 Subject: [PATCH 17/38] Update ADC to use GPIO and Pin --- src/per/adc.cpp | 173 +++++++++++++++++++----------------------------- src/per/adc.h | 20 +++--- 2 files changed, 77 insertions(+), 116 deletions(-) diff --git a/src/per/adc.cpp b/src/per/adc.cpp index c0fa4cbb9..a7dd6c352 100644 --- a/src/per/adc.cpp +++ b/src/per/adc.cpp @@ -10,73 +10,23 @@ static void Error_Handler() while(1) {} } -// Pinout by channel as dsy_gpio_pin -// TODO Figure out how to get this formatting -// to not suck.. -#define PIN_CHN_3 \ - { \ - DSY_GPIOA, 6 \ - } -#define PIN_CHN_4 \ - { \ - DSY_GPIOC, 4 \ - } -#define PIN_CHN_5 \ - { \ - DSY_GPIOB, 1 \ - } -#define PIN_CHN_7 \ - { \ - DSY_GPIOA, 7 \ - } -#define PIN_CHN_8 \ - { \ - DSY_GPIOC, 5 \ - } -#define PIN_CHN_9 \ - { \ - DSY_GPIOB, 0 \ - } -#define PIN_CHN_10 \ - { \ - DSY_GPIOC, 0 \ - } -#define PIN_CHN_11 \ - { \ - DSY_GPIOC, 1 \ - } -#define PIN_CHN_12 \ - { \ - DSY_GPIOC, 2 \ - } -#define PIN_CHN_13 \ - { \ - DSY_GPIOC, 3 \ - } -#define PIN_CHN_14 \ - { \ - DSY_GPIOA, 2 \ - } -#define PIN_CHN_15 \ - { \ - DSY_GPIOA, 3 \ - } -#define PIN_CHN_16 \ - { \ - DSY_GPIOA, 0 \ - } -#define PIN_CHN_17 \ - { \ - DSY_GPIOA, 1 \ - } -#define PIN_CHN_18 \ - { \ - DSY_GPIOA, 4 \ - } -#define PIN_CHN_19 \ - { \ - DSY_GPIOA, 5 \ - } +// Pinout by channel +constexpr Pin PIN_CHN_3 = Pin(PORTA, 6); +constexpr Pin PIN_CHN_4 = Pin(PORTC, 4); +constexpr Pin PIN_CHN_5 = Pin(PORTB, 1); +constexpr Pin PIN_CHN_7 = Pin(PORTA, 7); +constexpr Pin PIN_CHN_8 = Pin(PORTC, 5); +constexpr Pin PIN_CHN_9 = Pin(PORTB, 0); +constexpr Pin PIN_CHN_10 = Pin(PORTC, 0); +constexpr Pin PIN_CHN_11 = Pin(PORTC, 1); +constexpr Pin PIN_CHN_12 = Pin(PORTC, 2); +constexpr Pin PIN_CHN_13 = Pin(PORTC, 3); +constexpr Pin PIN_CHN_14 = Pin(PORTA, 2); +constexpr Pin PIN_CHN_15 = Pin(PORTA, 3); +constexpr Pin PIN_CHN_16 = Pin(PORTA, 0); +constexpr Pin PIN_CHN_17 = Pin(PORTA, 1); +constexpr Pin PIN_CHN_18 = Pin(PORTA, 4); +constexpr Pin PIN_CHN_19 = Pin(PORTA, 5); #define DSY_ADC_MAX_MUX_CHANNELS 8 #define DSY_ADC_MAX_RESOLUTION 65536.0f @@ -162,13 +112,13 @@ static int get_num_mux_pins_required(int num_mux_ch) return 0; } static void - write_mux_value(uint8_t chn, uint8_t idx, uint8_t num_mux_pins_to_write); -static const uint32_t adc_channel_from_pin(dsy_gpio_pin* pin); +write_mux_value(uint8_t chn, uint8_t idx, uint8_t num_mux_pins_to_write); +static const uint32_t adc_channel_from_pin(Pin pin); -static const uint32_t adc_channel_from_pin(dsy_gpio_pin* pin) +static const uint32_t adc_channel_from_pin(Pin pin) { // For now just a rough switch case for all ADC_CHANNEL values - dsy_gpio_pin adcpins[DSY_ADC_MAX_CHANNELS] = { + Pin adcpins[DSY_ADC_MAX_CHANNELS] = { PIN_CHN_3, PIN_CHN_4, PIN_CHN_5, @@ -188,7 +138,7 @@ static const uint32_t adc_channel_from_pin(dsy_gpio_pin* pin) }; for(size_t i = 0; i < DSY_ADC_MAX_CHANNELS; i++) { - if(dsy_pin_cmp(&adcpins[i], pin)) + if(adcpins[i] == pin) return dsy_adc_channel_map[i]; } return 0; // we should check what zero actually means in this context. @@ -199,34 +149,43 @@ static dsy_adc adc; // Begin AdcChannelConfig Implementations -void AdcChannelConfig::InitSingle(dsy_gpio_pin pin) +void AdcChannelConfig::InitSingle(Pin pin) { - pin_.pin = pin; - mux_channels_ = 0; - pin_.mode = DSY_GPIO_MODE_ANALOG; - pin_.pull = DSY_GPIO_NOPULL; + GPIO::Config& pin_config = pin_.GetConfig(); + + pin_config.pin = pin; + mux_channels_ = 0; + pin_config.mode = GPIO::Mode::ANALOG; + pin_config.pull = GPIO::Pull::NOPULL; } -void AdcChannelConfig::InitMux(dsy_gpio_pin adc_pin, - size_t mux_channels, - dsy_gpio_pin mux_0, - dsy_gpio_pin mux_1, - dsy_gpio_pin mux_2) +void AdcChannelConfig::InitMux(Pin adc_pin, + size_t mux_channels, + Pin mux_0, + Pin mux_1, + Pin mux_2) { size_t pins_to_init; + + GPIO::Config& pin_config = pin_.GetConfig(); + // Init ADC Pin - pin_.pin = adc_pin; - pin_.mode = DSY_GPIO_MODE_ANALOG; - pin_.pull = DSY_GPIO_NOPULL; + pin_config.pin = adc_pin; + pin_config.mode = GPIO::Mode::ANALOG; + pin_config.pull = GPIO::Pull::NOPULL; + // Init Muxes - mux_pin_[0].pin = mux_0; - mux_pin_[1].pin = mux_1; - mux_pin_[2].pin = mux_2; - mux_channels_ = mux_channels < 8 ? mux_channels : 8; - pins_to_init = get_num_mux_pins_required(mux_channels_); + mux_pin_[0].GetConfig().pin = mux_0; + mux_pin_[1].GetConfig().pin = mux_1; + mux_pin_[2].GetConfig().pin = mux_2; + + mux_channels_ = mux_channels < 8 ? mux_channels : 8; + pins_to_init = get_num_mux_pins_required(mux_channels_); for(size_t i = 0; i < pins_to_init; i++) { - mux_pin_[i].mode = DSY_GPIO_MODE_OUTPUT_PP; - mux_pin_[i].pull = DSY_GPIO_NOPULL; + GPIO::Config& mux_pin_config = mux_pin_[i].GetConfig(); + + mux_pin_config.mode = GPIO::Mode::OUTPUT; + mux_pin_config.pull = GPIO::Pull::NOPULL; } } @@ -365,10 +324,10 @@ void AdcHandle::Init(AdcChannelConfig* cfg, sConfig.Offset = 0; for(uint8_t i = 0; i < adc.channels; i++) { - const auto& cfg = adc.pin_cfg[i]; + AdcChannelConfig& cfg = adc.pin_cfg[i]; // init ADC pin - dsy_gpio_init(&cfg.pin_); + cfg.pin_.Init(); // init mux pins (if any) adc.num_mux_pins_required[i] @@ -376,11 +335,11 @@ void AdcHandle::Init(AdcChannelConfig* cfg, if(cfg.mux_channels_ > 0) { for(int j = 0; j < adc.num_mux_pins_required[i]; j++) - dsy_gpio_init(&cfg.mux_pin_[j]); + cfg.mux_pin_[j].Init(); } // init adc channel sequence - sConfig.Channel = adc_channel_from_pin(&adc.pin_cfg[i].pin_.pin); + sConfig.Channel = adc_channel_from_pin(adc.pin_cfg[i].pin_.GetConfig().pin); sConfig.Rank = dsy_adc_rank_map[i]; if(HAL_ADC_ConfigChannel(&adc.hadc1, &sConfig) != HAL_OK) { @@ -440,18 +399,17 @@ float AdcHandle::GetMuxFloat(uint8_t chn, uint8_t idx) const static void write_mux_value(uint8_t chn, uint8_t idx, uint8_t num_mux_pins_to_write) { - dsy_gpio *p0, *p1, *p2; - p0 = &adc.pin_cfg[chn].mux_pin_[0]; - dsy_gpio_write(p0, (idx & 0x01) > 0); + GPIO& p0 = adc.pin_cfg[chn].mux_pin_[0]; + p0.Write((idx & 0x01) > 0); if(num_mux_pins_to_write > 1) { - p1 = &adc.pin_cfg[chn].mux_pin_[1]; - dsy_gpio_write(p1, (idx & 0x02) > 0); + GPIO& p1 = adc.pin_cfg[chn].mux_pin_[1]; + p1.Write((idx & 0x02) > 0); } if(num_mux_pins_to_write > 2) { - p2 = &adc.pin_cfg[chn].mux_pin_[2]; - dsy_gpio_write(p2, (idx & 0x04) > 0); + GPIO& p2 = adc.pin_cfg[chn].mux_pin_[2]; + p2.Write((idx & 0x04) > 0); } } @@ -534,9 +492,9 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle) // deinit pins for(size_t i = 0; i < adc.channels; i++) { - dsy_gpio_deinit(&adc.pin_cfg[i].pin_); + adc.pin_cfg[i].pin_.DeInit(); for(size_t muxCh = 0; muxCh < adc.num_mux_pins_required[i]; muxCh++) - dsy_gpio_deinit(&adc.pin_cfg[i].mux_pin_[muxCh]); + adc.pin_cfg[i].mux_pin_[muxCh].DeInit(); } HAL_DMA_DeInit(adcHandle->DMA_Handle); } @@ -544,7 +502,10 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle) extern "C" { - void DMA1_Stream2_IRQHandler(void) { HAL_DMA_IRQHandler(&adc.hdma_adc1); } + void DMA1_Stream2_IRQHandler(void) + { + HAL_DMA_IRQHandler(&adc.hdma_adc1); + } void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) { diff --git a/src/per/adc.h b/src/per/adc.h index bb3161a04..a685e6325 100644 --- a/src/per/adc.h +++ b/src/per/adc.h @@ -42,7 +42,7 @@ struct AdcChannelConfig /** Initializes a single ADC pin as an ADC. \param pin Pin to init. */ - void InitSingle(dsy_gpio_pin pin); + void InitSingle(Pin pin); /** Initializes a single ADC pin as a Multiplexed ADC. @@ -56,15 +56,15 @@ struct AdcChannelConfig \param mux_2 Third mux pin \param adc_pin & */ - void InitMux(dsy_gpio_pin adc_pin, - size_t mux_channels, - dsy_gpio_pin mux_0, - dsy_gpio_pin mux_1 = {DSY_GPIOX, 0}, - dsy_gpio_pin mux_2 = {DSY_GPIOX, 0}); - - dsy_gpio pin_; /**< & */ - dsy_gpio mux_pin_[MUX_SEL_LAST]; /**< & */ - uint8_t mux_channels_; /**< & */ + void InitMux(Pin adc_pin, + size_t mux_channels, + Pin mux_0, + Pin mux_1 = Pin(PORTX, 0), + Pin mux_2 = Pin(PORTX, 0)); + + GPIO pin_; /**< & */ + GPIO mux_pin_[MUX_SEL_LAST]; /**< & */ + uint8_t mux_channels_; /**< & */ }; /** From 89d0cbe816d85366e182870eb6ffa30c491fa707 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 22:02:28 -0400 Subject: [PATCH 18/38] Update system to use GPIO and Pin --- src/sys/system.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/sys/system.cpp b/src/sys/system.cpp index acead70e2..1444e85da 100644 --- a/src/sys/system.cpp +++ b/src/sys/system.cpp @@ -297,14 +297,13 @@ void System::DelayTicks(uint32_t delay_ticks) void System::ResetToBootloader() { // Initialize Boot Pin - dsy_gpio_pin bootpin = {DSY_GPIOG, 3}; - dsy_gpio pin; - pin.mode = DSY_GPIO_MODE_OUTPUT_PP; - pin.pin = bootpin; - dsy_gpio_init(&pin); + constexpr Pin bootpin = Pin(PORTG, 3); + + GPIO pin; + pin.Init(bootpin, GPIO::Mode::OUTPUT); // Pull Pin HIGH - dsy_gpio_write(&pin, 1); + pin.Write(1); // wait a few ms for cap to charge HAL_Delay(10); @@ -414,9 +413,9 @@ void System::ConfigureClocks() // New Timing PeriphClkInitStruct.PLL2.PLL2N = 12; // Max supported freq of FMC; PeriphClkInitStruct.PLL2.PLL2M = 1; - PeriphClkInitStruct.PLL2.PLL2P = 8; // 25MHz - PeriphClkInitStruct.PLL2.PLL2Q = 2; // 100MHz - PeriphClkInitStruct.PLL2.PLL2R = 1; // 200MHz + PeriphClkInitStruct.PLL2.PLL2P = 8; // 25MHz + PeriphClkInitStruct.PLL2.PLL2Q = 2; // 100MHz + PeriphClkInitStruct.PLL2.PLL2R = 1; // 200MHz PeriphClkInitStruct.PLL2.PLL2FRACN = 4096; From 25a1f5c8173baf875b19c28c0cf8884cb886c9ba Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 22:09:08 -0400 Subject: [PATCH 19/38] Update multi-peripheral SPI driver with GPIO/Pin --- src/per/spiMultislave.cpp | 9 +++------ src/per/spiMultislave.h | 10 +++++----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/per/spiMultislave.cpp b/src/per/spiMultislave.cpp index 4d8329ef9..5ee217c6d 100644 --- a/src/per/spiMultislave.cpp +++ b/src/per/spiMultislave.cpp @@ -11,10 +11,7 @@ SpiHandle::Result MultiSlaveSpiHandle::Init(const Config& config) for(size_t i = 0; i < config_.num_devices; i++) { - nss_pins[i].pin = config_.pin_config.nss[i]; - nss_pins[i].mode = DSY_GPIO_MODE_OUTPUT_PP; - nss_pins[i].pull = DSY_GPIO_NOPULL; - dsy_gpio_init(&nss_pins[i]); + nss_pins[i].Init(config_.pin_config.nss[i], GPIO::Mode::OUTPUT); DisableDevice(i); } @@ -164,12 +161,12 @@ int MultiSlaveSpiHandle::CheckError() void MultiSlaveSpiHandle::EnableDevice(size_t device_index) { - dsy_gpio_write(&nss_pins[device_index], 0); + nss_pins[device_index].Write(0); } void MultiSlaveSpiHandle::DisableDevice(size_t device_index) { - dsy_gpio_write(&nss_pins[device_index], 1); + nss_pins[device_index].Write(1); } void MultiSlaveSpiHandle::DmaStartCallback(void* context) diff --git a/src/per/spiMultislave.h b/src/per/spiMultislave.h index b6753caee..846c6b977 100644 --- a/src/per/spiMultislave.h +++ b/src/per/spiMultislave.h @@ -25,10 +25,10 @@ class MultiSlaveSpiHandle { struct { - dsy_gpio_pin sclk; /**< & */ - dsy_gpio_pin miso; /**< & */ - dsy_gpio_pin mosi; /**< & */ - dsy_gpio_pin nss[max_num_devices_]; + Pin sclk; /**< & */ + Pin miso; /**< & */ + Pin mosi; /**< & */ + Pin nss[max_num_devices_]; } pin_config; SpiHandle::Config::Peripheral periph; @@ -154,7 +154,7 @@ class MultiSlaveSpiHandle Config config_; SpiHandle spiHandle_; - dsy_gpio nss_pins[max_num_devices_]; + GPIO nss_pins[max_num_devices_]; struct DmaTransfer { From 3d0ca1854c12d2231ae583f41d3c037c0fbba638 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 23:21:23 -0400 Subject: [PATCH 20/38] Update Midi to use Pin --- src/hid/midi.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hid/midi.h b/src/hid/midi.h index 16dcd1dc6..5b725c3af 100644 --- a/src/hid/midi.h +++ b/src/hid/midi.h @@ -28,14 +28,14 @@ class MidiUartTransport struct Config { UartHandler::Config::Peripheral periph; - dsy_gpio_pin rx; - dsy_gpio_pin tx; + Pin rx; + Pin tx; Config() { periph = UartHandler::Config::Peripheral::USART_1; - rx = {DSY_GPIOB, 7}; - tx = {DSY_GPIOB, 6}; + rx = Pin(PORTB, 7); + tx = Pin(PORTB, 6); } }; From 66b678f69b7c585b51e6d0b71ae8ac5828931ee2 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 23:21:48 -0400 Subject: [PATCH 21/38] Update TLV493D to use Pin --- src/dev/tlv493d.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dev/tlv493d.h b/src/dev/tlv493d.h index d64d8e540..b0b43e22e 100644 --- a/src/dev/tlv493d.h +++ b/src/dev/tlv493d.h @@ -36,8 +36,8 @@ class Tlv493dI2CTransport { I2CHandle::Config::Peripheral periph; I2CHandle::Config::Speed speed; - dsy_gpio_pin scl; - dsy_gpio_pin sda; + Pin scl; + Pin sda; uint8_t address; @@ -46,8 +46,8 @@ class Tlv493dI2CTransport periph = I2CHandle::Config::Peripheral::I2C_1; speed = I2CHandle::Config::Speed::I2C_400KHZ; - scl = {DSY_GPIOB, 8}; - sda = {DSY_GPIOB, 9}; + scl = Pin(PORTB, 8); + sda = Pin(PORTB, 9); address = TLV493D_ADDRESS1; } From a163e0aa209522d280b63d26fac7b67bf7a752f7 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sat, 27 May 2023 23:23:12 -0400 Subject: [PATCH 22/38] Update MCP23x17 and MAX11300 to use Pin --- src/dev/max11300.h | 8 ++++---- src/dev/mcp23x17.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dev/max11300.h b/src/dev/max11300.h index 281104582..fbac62226 100644 --- a/src/dev/max11300.h +++ b/src/dev/max11300.h @@ -128,10 +128,10 @@ class MAX11300MultiSlaveSpiTransport { struct PinConfig { - dsy_gpio_pin nss[numDevices] = {{DSY_GPIOG, 10}}; // Pin 7 - dsy_gpio_pin mosi = {DSY_GPIOB, 5}; // Pin 10 - dsy_gpio_pin miso = {DSY_GPIOB, 4}; // Pin 9 - dsy_gpio_pin sclk = {DSY_GPIOG, 11}; // Pin 8 + Pin nss[numDevices] = {Pin(PORTG, 10)}; // Pin 7 + Pin mosi = Pin(PORTB, 5); // Pin 10 + Pin miso = Pin(PORTB, 4); // Pin 9 + Pin sclk = Pin(PORTG, 11); // Pin 8 } pin_config; SpiHandle::Config::Peripheral periph diff --git a/src/dev/mcp23x17.h b/src/dev/mcp23x17.h index fcc4db790..ad8481a8f 100644 --- a/src/dev/mcp23x17.h +++ b/src/dev/mcp23x17.h @@ -90,8 +90,8 @@ class Mcp23017Transport i2c_config.periph = I2CHandle::Config::Peripheral::I2C_1; i2c_config.speed = I2CHandle::Config::Speed::I2C_1MHZ; i2c_config.mode = I2CHandle::Config::Mode::I2C_MASTER; - i2c_config.pin_config.scl = {DSY_GPIOB, 8}; - i2c_config.pin_config.sda = {DSY_GPIOB, 9}; + i2c_config.pin_config.scl = Pin(PORTB, 8); + i2c_config.pin_config.sda = Pin(PORTB, 9); i2c_address = 0x27; } }; From 9967424d0f38ec45fd1c89b637bfff50d421d6ed Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sun, 28 May 2023 23:46:08 -0400 Subject: [PATCH 23/38] Update DAC driver to use GPIO and Pin --- src/per/dac.cpp | 55 +++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/src/per/dac.cpp b/src/per/dac.cpp index 23c34bf20..012e62059 100644 --- a/src/per/dac.cpp +++ b/src/per/dac.cpp @@ -17,9 +17,9 @@ class DacHandle::Impl DacHandle::Result Init(const DacHandle::Config &config); const DacHandle::Config &GetConfig() const { return config_; } DacHandle::Result - Start(uint16_t *buffer, size_t size, DacHandle::DacCallback cb); - DacHandle::Result Start(uint16_t * buffer_1, - uint16_t * buffer_2, + Start(uint16_t *buffer, size_t size, DacHandle::DacCallback cb); + DacHandle::Result Start(uint16_t *buffer_1, + uint16_t *buffer_2, size_t size, DacHandle::DacCallback cb); DacHandle::Result Stop(); @@ -45,14 +45,15 @@ class DacHandle::Impl DAC_HandleTypeDef hal_dac_; /**< ST HAL DAC Handle*/ DMA_HandleTypeDef - hal_dac_dma_[2]; /**< ST HAL DMA Hande (one per available channel) */ + hal_dac_dma_[2]; /**< ST HAL DMA Hande (one per available channel) */ TIM_HandleTypeDef hal_tim_; private: DacHandle::Config config_; /**< Config Struct for initialization */ size_t buff_size_; - uint16_t * buff_[2]; + uint16_t *buff_[2]; DacHandle::DacCallback callback_; + GPIO d1, d2; }; // ================================================================ @@ -109,9 +110,9 @@ DacHandle::Result DacHandle::Impl::Init(const DacHandle::Config &config) // Base tim freq is PClk2 * 2 (200/240MHz depending on system configuration). tim_base_freq = System:: GetPClk2Freq(); // 100MHz (or 120MHz) depending on CPU Freq. - target_freq = config_.target_samplerate == 0 - ? 48000 - : config_.target_samplerate; + target_freq = config_.target_samplerate == 0 + ? 48000 + : config_.target_samplerate; period = tim_base_freq / target_freq; hal_tim_.Init.Period = period; hal_tim_.Init.Prescaler = 1; @@ -158,11 +159,11 @@ DacHandle::Impl::Start(uint16_t *buffer, size_t size, DacHandle::DacCallback cb) { if(config_.mode != Mode::DMA || config_.chn == Channel::BOTH) return Result::ERR; - callback_ = cb; - buff_[0] = buffer; - buff_size_ = size; - uint32_t bd = config_.bitdepth == BitDepth::BITS_8 ? DAC_ALIGN_8B_R - : DAC_ALIGN_12B_R; + callback_ = cb; + buff_[0] = buffer; + buff_size_ = size; + uint32_t bd = config_.bitdepth == BitDepth::BITS_8 ? DAC_ALIGN_8B_R + : DAC_ALIGN_12B_R; uint32_t chn = config_.chn == Channel::ONE ? DAC_CHANNEL_1 : DAC_CHANNEL_2; HAL_DAC_Start_DMA(&hal_dac_, chn, (uint32_t *)buff_[0], size, bd); HAL_TIM_Base_Start(&hal_tim_); @@ -171,8 +172,8 @@ DacHandle::Impl::Start(uint16_t *buffer, size_t size, DacHandle::DacCallback cb) /** Not fully implemented -- I had the intention of setting up both DACs to work from a single callback, which ** it seems like will require a bit more setup in the Init (basically set it to dual mode). */ -DacHandle::Result DacHandle::Impl::Start(uint16_t * buffer_1, - uint16_t * buffer_2, +DacHandle::Result DacHandle::Impl::Start(uint16_t *buffer_1, + uint16_t *buffer_2, size_t size, DacHandle::DacCallback cb) { @@ -188,7 +189,7 @@ DacHandle::Result DacHandle::Impl::Start(uint16_t * buffer_1, buff_[1] = buffer_2; buff_size_ = size; bd = config_.bitdepth == BitDepth::BITS_8 ? DAC_ALIGN_8B_R - : DAC_ALIGN_12B_R; + : DAC_ALIGN_12B_R; // Start the DACs and then start the time source. HAL_DAC_Start_DMA(&hal_dac_, DAC_CHANNEL_1, (uint32_t *)buff_[0], size, bd); @@ -238,19 +239,13 @@ void DacHandle::Impl::InitPins() if(ChannelOneActive()) { // Init PA4 as Analog - dsy_gpio d1; - d1.pin = {DSY_GPIOA, 4}; - d1.mode = DSY_GPIO_MODE_ANALOG; - dsy_gpio_init(&d1); + d1.Init(Pin(PORTA, 4), GPIO::Mode::ANALOG); } if(ChannelTwoActive()) { // Init PA5 as Analog - dsy_gpio d2; - d2.pin = {DSY_GPIOA, 5}; - d2.mode = DSY_GPIO_MODE_ANALOG; - dsy_gpio_init(&d2); + d2.Init(Pin(PORTA, 5), GPIO::Mode::ANALOG); } } @@ -309,15 +304,11 @@ void DacHandle::Impl::DeInitPins() { if(ChannelOneActive()) { - dsy_gpio d1; - d1.pin = {DSY_GPIOA, 4}; - dsy_gpio_deinit(&d1); + d1.DeInit(); } if(ChannelTwoActive()) { - dsy_gpio d2; - d2.pin = {DSY_GPIOA, 5}; - dsy_gpio_deinit(&d2); + d2.DeInit(); } } @@ -453,8 +444,8 @@ DacHandle::Start(uint16_t *buffer, size_t size, DacHandle::DacCallback cb) return pimpl_->Start(buffer, size, cb); } -DacHandle::Result DacHandle::Start(uint16_t * buffer_1, - uint16_t * buffer_2, +DacHandle::Result DacHandle::Start(uint16_t *buffer_1, + uint16_t *buffer_2, size_t size, DacHandle::DacCallback cb) { From 2e3e75aec721b8c92ee9dc74b8859e4e1e3297fd Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Sun, 28 May 2023 23:49:32 -0400 Subject: [PATCH 24/38] Update I2C driver to use GPIO and Pin --- src/per/i2c.cpp | 19 ++++++++----------- src/per/i2c.h | 4 ++-- src/util/hal_map.h | 47 +++++++++++++++++++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/src/per/i2c.cpp b/src/per/i2c.cpp index 3a8476105..533749471 100644 --- a/src/per/i2c.cpp +++ b/src/per/i2c.cpp @@ -1,10 +1,7 @@ #include "per/i2c.h" #include "sys/system.h" #include "util/scopedirqblocker.h" -extern "C" -{ #include "util/hal_map.h" -} namespace daisy { @@ -636,11 +633,11 @@ void I2CHandle::Impl::InitPins() default: break; } - port = dsy_hal_map_get_port(&config_.pin_config.scl); - GPIO_InitStruct.Pin = dsy_hal_map_get_pin(&config_.pin_config.scl); + port = GetHALPort(config_.pin_config.scl); + GPIO_InitStruct.Pin = GetHALPin(config_.pin_config.scl); HAL_GPIO_Init(port, &GPIO_InitStruct); - port = dsy_hal_map_get_port(&config_.pin_config.sda); - GPIO_InitStruct.Pin = dsy_hal_map_get_pin(&config_.pin_config.sda); + port = GetHALPort(config_.pin_config.sda); + GPIO_InitStruct.Pin = GetHALPin(config_.pin_config.sda); HAL_GPIO_Init(port, &GPIO_InitStruct); } @@ -648,11 +645,11 @@ void I2CHandle::Impl::DeinitPins() { GPIO_TypeDef* port; uint16_t pin; - port = dsy_hal_map_get_port(&config_.pin_config.scl); - pin = dsy_hal_map_get_pin(&config_.pin_config.scl); + port = GetHALPort(config_.pin_config.scl); + pin = GetHALPin(config_.pin_config.scl); HAL_GPIO_DeInit(port, pin); - port = dsy_hal_map_get_port(&config_.pin_config.sda); - pin = dsy_hal_map_get_pin(&config_.pin_config.sda); + port = GetHALPort(config_.pin_config.sda); + pin = GetHALPin(config_.pin_config.sda); HAL_GPIO_DeInit(port, pin); } diff --git a/src/per/i2c.h b/src/per/i2c.h index f7d7a89d1..4635c2229 100644 --- a/src/per/i2c.h +++ b/src/per/i2c.h @@ -56,8 +56,8 @@ class I2CHandle Peripheral periph; /**< & */ struct { - dsy_gpio_pin scl; /**< & */ - dsy_gpio_pin sda; /**< & */ + Pin scl; /**< & */ + Pin sda; /**< & */ } pin_config; /**< & */ Speed speed; /**< & */ diff --git a/src/util/hal_map.h b/src/util/hal_map.h index acb7d23e4..c8311315c 100644 --- a/src/util/hal_map.h +++ b/src/util/hal_map.h @@ -7,28 +7,61 @@ /** @addtogroup utility @{ */ +#ifdef __cplusplus +namespace daisy +{ +constexpr uint32_t GetHALPin(Pin p) +{ + return (1 << p.pin); +} +constexpr GPIO_TypeDef *GetHALPort(Pin p) +{ + switch(p.port) + { + case PORTA: return GPIOA; + case PORTB: return GPIOB; + case PORTC: return GPIOC; + case PORTD: return GPIOD; + case PORTE: return GPIOE; + case PORTF: return GPIOF; + case PORTG: return GPIOG; + case PORTH: return GPIOH; + case PORTI: return GPIOI; + case PORTJ: return GPIOJ; + case PORTK: return GPIOK; + default: return NULL; + } +} +} // namespace daisy +extern "C" +{ +#endif -/** global structs, and helper functions for interfacing with the stm32 HAL library + /** global structs, and helper functions for interfacing with the stm32 HAL library while it remains a dependancy. This file should only be included from source files (c/cpp) Including it from a header within libdaisy would expose the entire HAL to the users. This should be an option for users, but should not be required. */ -/** \param *p Pin pin to get + /** \param *p Pin pin to get \return HAL GPIO_TypeDef as used in the HAL from a dsy_gpio_pin input. */ -GPIO_TypeDef *dsy_hal_map_get_port(const dsy_gpio_pin *p); + GPIO_TypeDef *dsy_hal_map_get_port(const dsy_gpio_pin *p); -/** \param *p Pin pin to get + /** \param *p Pin pin to get \return HAL GPIO Pin as used in the HAL from a dsy_gpio_pin input. */ -uint16_t dsy_hal_map_get_pin(const dsy_gpio_pin *p); + uint16_t dsy_hal_map_get_pin(const dsy_gpio_pin *p); -/** \param port port clock to enable + /** \param port port clock to enable */ -void dsy_hal_map_gpio_clk_enable(dsy_gpio_port port); + void dsy_hal_map_gpio_clk_enable(dsy_gpio_port port); + +#ifdef __cplusplus +} +#endif #endif /** @} */ From d90db674c0aede63a59abcee218351c9a07f1899 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Mon, 29 May 2023 00:00:52 -0400 Subject: [PATCH 25/38] Update UART to use GPIO and Pin --- src/per/uart.cpp | 128 +++++++++++++++++++++++++++------------------ src/per/uart.h | 4 +- src/util/hal_map.h | 18 +++++++ 3 files changed, 97 insertions(+), 53 deletions(-) diff --git a/src/per/uart.cpp b/src/per/uart.cpp index 07fef2662..13194a530 100644 --- a/src/per/uart.cpp +++ b/src/per/uart.cpp @@ -675,59 +675,59 @@ int UartHandler::Impl::CheckError() typedef struct { - dsy_gpio_pin pin; - uint8_t alt; + Pin pin; + uint8_t alt; } pin_alt; -pin_alt pins_none = {{DSY_GPIOX, 0}, 255}; +pin_alt pins_none = {Pin(PORTX, 0), 255}; //valid pins per periph, and the alt they're on -pin_alt usart1_pins_tx[] = {{{DSY_GPIOB, 6}, GPIO_AF7_USART1}, - {{DSY_GPIOB, 14}, GPIO_AF4_USART1}, +pin_alt usart1_pins_tx[] = {{Pin(PORTB, 6), GPIO_AF7_USART1}, + {Pin(PORTB, 14), GPIO_AF4_USART1}, pins_none}; -pin_alt usart1_pins_rx[] = {{{DSY_GPIOB, 7}, GPIO_AF7_USART1}, - {{DSY_GPIOB, 15}, GPIO_AF4_USART1}, +pin_alt usart1_pins_rx[] = {{Pin(PORTB, 7), GPIO_AF7_USART1}, + {Pin(PORTB, 15), GPIO_AF4_USART1}, pins_none}; pin_alt usart2_pins_tx[] - = {{{DSY_GPIOA, 2}, GPIO_AF7_USART2}, pins_none, pins_none}; + = {{Pin(PORTA, 2), GPIO_AF7_USART2}, pins_none, pins_none}; pin_alt usart2_pins_rx[] - = {{{DSY_GPIOA, 3}, GPIO_AF7_USART2}, pins_none, pins_none}; + = {{Pin(PORTA, 3), GPIO_AF7_USART2}, pins_none, pins_none}; pin_alt usart3_pins_tx[] - = {{{DSY_GPIOC, 10}, GPIO_AF7_USART3}, pins_none, pins_none}; + = {{Pin(PORTC, 10), GPIO_AF7_USART3}, pins_none, pins_none}; pin_alt usart3_pins_rx[] - = {{{DSY_GPIOC, 11}, GPIO_AF7_USART3}, pins_none, pins_none}; + = {{Pin(PORTC, 11), GPIO_AF7_USART3}, pins_none, pins_none}; -pin_alt uart4_pins_tx[] = {{{DSY_GPIOB, 9}, GPIO_AF8_UART4}, - {{DSY_GPIOC, 10}, GPIO_AF8_UART4}, - {{DSY_GPIOA, 0}, GPIO_AF8_UART4}}; -pin_alt uart4_pins_rx[] = {{{DSY_GPIOB, 8}, GPIO_AF8_UART4}, - {{DSY_GPIOC, 11}, GPIO_AF8_UART4}, - {{DSY_GPIOA, 1}, GPIO_AF8_UART4}}; +pin_alt uart4_pins_tx[] = {{Pin(PORTB, 9), GPIO_AF8_UART4}, + {Pin(PORTC, 10), GPIO_AF8_UART4}, + {Pin(PORTA, 0), GPIO_AF8_UART4}}; +pin_alt uart4_pins_rx[] = {{Pin(PORTB, 8), GPIO_AF8_UART4}, + {Pin(PORTC, 11), GPIO_AF8_UART4}, + {Pin(PORTA, 1), GPIO_AF8_UART4}}; -pin_alt uart5_pins_tx[] = {{{DSY_GPIOC, 12}, GPIO_AF8_UART5}, - {{DSY_GPIOB, 6}, GPIO_AF14_UART5}, +pin_alt uart5_pins_tx[] = {{Pin(PORTC, 12), GPIO_AF8_UART5}, + {Pin(PORTB, 6), GPIO_AF14_UART5}, pins_none}; -pin_alt uart5_pins_rx[] = {{{DSY_GPIOB, 12}, GPIO_AF14_UART5}, - {{DSY_GPIOD, 2}, GPIO_AF8_UART5}, - {{DSY_GPIOB, 5}, GPIO_AF14_UART5}}; +pin_alt uart5_pins_rx[] = {{Pin(PORTB, 12), GPIO_AF14_UART5}, + {Pin(PORTD, 2), GPIO_AF8_UART5}, + {Pin(PORTB, 5), GPIO_AF14_UART5}}; pin_alt usart6_pins_tx[] = {pins_none, pins_none, pins_none}; pin_alt usart6_pins_rx[] - = {{{DSY_GPIOG, 9}, GPIO_AF7_USART6}, pins_none, pins_none}; + = {{Pin(PORTG, 9), GPIO_AF7_USART6}, pins_none, pins_none}; pin_alt uart7_pins_tx[] - = {{{DSY_GPIOB, 4}, GPIO_AF11_UART7}, pins_none, pins_none}; + = {{Pin(PORTB, 4), GPIO_AF11_UART7}, pins_none, pins_none}; pin_alt uart7_pins_rx[] = {pins_none, pins_none, pins_none}; pin_alt uart8_pins_tx[] = {pins_none, pins_none, pins_none}; pin_alt uart8_pins_rx[] = {pins_none, pins_none, pins_none}; pin_alt lpuart1_pins_tx[] - = {{{DSY_GPIOB, 6}, GPIO_AF8_LPUART}, pins_none, pins_none}; + = {{Pin(PORTB, 6), GPIO_AF8_LPUART}, pins_none, pins_none}; pin_alt lpuart1_pins_rx[] - = {{{DSY_GPIOB, 7}, GPIO_AF8_LPUART}, pins_none, pins_none}; + = {{Pin(PORTB, 7), GPIO_AF8_LPUART}, pins_none, pins_none}; //an array to hold everything pin_alt* pins_periphs[] = {usart1_pins_tx, @@ -749,17 +749,16 @@ pin_alt* pins_periphs[] = {usart1_pins_tx, lpuart1_pins_tx, lpuart1_pins_rx}; -UartHandler::Result -checkPinMatch(GPIO_InitTypeDef* init, dsy_gpio_pin pin, int p_num) +UartHandler::Result checkPinMatch(GPIO_InitTypeDef* init, Pin pin, int p_num) { for(int i = 0; i < 3; i++) { - if(dsy_pin_cmp(&pins_periphs[p_num][i].pin, &pins_none.pin)) + if(pins_periphs[p_num][i].pin == pins_none.pin) { /* skip */ } - else if(dsy_pin_cmp(&pins_periphs[p_num][i].pin, &pin)) + else if(pins_periphs[p_num][i].pin == pin) { init->Alternate = pins_periphs[p_num][i].alt; return UartHandler::Result::OK; @@ -779,7 +778,7 @@ UartHandler::Result UartHandler::Impl::InitPins() int per_num = 2 * (int)(config_.periph); - if(config_.pin_config.tx.port != DSY_GPIOX) + if(config_.pin_config.tx.port != PORTX) { //check tx against periph if(checkPinMatch(&GPIO_InitStruct, config_.pin_config.tx, per_num) @@ -789,12 +788,12 @@ UartHandler::Result UartHandler::Impl::InitPins() } //setup tx pin - GPIO_TypeDef* port = dsy_hal_map_get_port(&config_.pin_config.tx); - GPIO_InitStruct.Pin = dsy_hal_map_get_pin(&config_.pin_config.tx); + GPIO_TypeDef* port = GetHALPort(config_.pin_config.tx); + GPIO_InitStruct.Pin = GetHALPin(config_.pin_config.tx); HAL_GPIO_Init(port, &GPIO_InitStruct); } - if(config_.pin_config.rx.port != DSY_GPIOX) + if(config_.pin_config.rx.port != PORTX) { //check rx against periph if(checkPinMatch(&GPIO_InitStruct, config_.pin_config.rx, per_num + 1) @@ -804,8 +803,8 @@ UartHandler::Result UartHandler::Impl::InitPins() } //setup rx pin - GPIO_TypeDef* port = dsy_hal_map_get_port(&config_.pin_config.rx); - GPIO_InitStruct.Pin = dsy_hal_map_get_pin(&config_.pin_config.rx); + GPIO_TypeDef* port = GetHALPort(config_.pin_config.rx); + GPIO_InitStruct.Pin = GetHALPin(config_.pin_config.rx); HAL_GPIO_Init(port, &GPIO_InitStruct); } @@ -814,12 +813,12 @@ UartHandler::Result UartHandler::Impl::InitPins() UartHandler::Result UartHandler::Impl::DeInitPins() { - GPIO_TypeDef* port = dsy_hal_map_get_port(&config_.pin_config.tx); - uint16_t pin = dsy_hal_map_get_pin(&config_.pin_config.tx); + GPIO_TypeDef* port = GetHALPort(config_.pin_config.tx); + uint16_t pin = GetHALPin(config_.pin_config.tx); HAL_GPIO_DeInit(port, pin); - port = dsy_hal_map_get_port(&config_.pin_config.rx); - pin = dsy_hal_map_get_pin(&config_.pin_config.rx); + port = GetHALPort(config_.pin_config.rx); + pin = GetHALPin(config_.pin_config.rx); HAL_GPIO_DeInit(port, pin); return Result::OK; @@ -836,8 +835,8 @@ void* UartHandler::Impl::next_callback_context_; void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) { UartHandler::Impl* handle = MapInstanceToHandle(uartHandle->Instance); - dsy_hal_map_gpio_clk_enable(handle->config_.pin_config.rx.port); - dsy_hal_map_gpio_clk_enable(handle->config_.pin_config.tx.port); + GPIOClockEnable(handle->config_.pin_config.rx); + GPIOClockEnable(handle->config_.pin_config.tx); switch(handle->config_.periph) { @@ -965,15 +964,42 @@ void UART_IRQHandler(UartHandler::Impl* handle) extern "C" { - void USART1_IRQHandler() { UART_IRQHandler(&uart_handles[0]); } - void USART2_IRQHandler() { UART_IRQHandler(&uart_handles[1]); } - void USART3_IRQHandler() { UART_IRQHandler(&uart_handles[2]); } - void UART4_IRQHandler() { UART_IRQHandler(&uart_handles[3]); } - void UART5_IRQHandler() { UART_IRQHandler(&uart_handles[4]); } - void USART6_IRQHandler() { UART_IRQHandler(&uart_handles[5]); } - void UART7_IRQHandler() { UART_IRQHandler(&uart_handles[6]); } - void UART8_IRQHandler() { UART_IRQHandler(&uart_handles[7]); } - void LPUART1_IRQHandler() { UART_IRQHandler(&uart_handles[8]); } + void USART1_IRQHandler() + { + UART_IRQHandler(&uart_handles[0]); + } + void USART2_IRQHandler() + { + UART_IRQHandler(&uart_handles[1]); + } + void USART3_IRQHandler() + { + UART_IRQHandler(&uart_handles[2]); + } + void UART4_IRQHandler() + { + UART_IRQHandler(&uart_handles[3]); + } + void UART5_IRQHandler() + { + UART_IRQHandler(&uart_handles[4]); + } + void USART6_IRQHandler() + { + UART_IRQHandler(&uart_handles[5]); + } + void UART7_IRQHandler() + { + UART_IRQHandler(&uart_handles[6]); + } + void UART8_IRQHandler() + { + UART_IRQHandler(&uart_handles[7]); + } + void LPUART1_IRQHandler() + { + UART_IRQHandler(&uart_handles[8]); + } } void HalUartDmaRxStreamCallback(void) diff --git a/src/per/uart.h b/src/per/uart.h index 197b45d9a..75baa6fc9 100644 --- a/src/per/uart.h +++ b/src/per/uart.h @@ -71,8 +71,8 @@ class UartHandler struct { - dsy_gpio_pin tx; /**< & */ - dsy_gpio_pin rx; /**< & */ + Pin tx; /**< & */ + Pin rx; /**< & */ } pin_config; /**< & */ Config() diff --git a/src/util/hal_map.h b/src/util/hal_map.h index c8311315c..3e1f09f1b 100644 --- a/src/util/hal_map.h +++ b/src/util/hal_map.h @@ -32,6 +32,24 @@ constexpr GPIO_TypeDef *GetHALPort(Pin p) default: return NULL; } } +inline void GPIOClockEnable(Pin p) +{ + switch(p.port) + { + case PORTA: __HAL_RCC_GPIOA_CLK_ENABLE(); return; + case PORTB: __HAL_RCC_GPIOB_CLK_ENABLE(); return; + case PORTC: __HAL_RCC_GPIOC_CLK_ENABLE(); return; + case PORTD: __HAL_RCC_GPIOD_CLK_ENABLE(); return; + case PORTE: __HAL_RCC_GPIOE_CLK_ENABLE(); return; + case PORTF: __HAL_RCC_GPIOF_CLK_ENABLE(); return; + case PORTG: __HAL_RCC_GPIOG_CLK_ENABLE(); return; + case PORTH: __HAL_RCC_GPIOH_CLK_ENABLE(); return; + case PORTI: __HAL_RCC_GPIOI_CLK_ENABLE(); return; + case PORTJ: __HAL_RCC_GPIOJ_CLK_ENABLE(); return; + case PORTK: __HAL_RCC_GPIOK_CLK_ENABLE(); return; + default: return; + } +} } // namespace daisy extern "C" From 660d5f0dcd11526ad923cedb5b7c5122222acc83 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Mon, 29 May 2023 00:07:37 -0400 Subject: [PATCH 26/38] Update SPI peripheral to use GPIO and Pin --- src/per/spi.cpp | 120 +++++++++++++++++++------------------- src/per/spi.h | 8 +-- src/per/spiMultislave.cpp | 2 +- 3 files changed, 65 insertions(+), 65 deletions(-) diff --git a/src/per/spi.cpp b/src/per/spi.cpp index 63f8ea61f..bac197c7a 100644 --- a/src/per/spi.cpp +++ b/src/per/spi.cpp @@ -712,60 +712,60 @@ SpiHandle::Result SpiHandle::Impl::BlockingTransmitAndReceive(uint8_t* tx_buff, typedef struct { - dsy_gpio_pin pin; - uint8_t alt; + Pin pin; + uint8_t alt; } pin_alt_spi; -static pin_alt_spi pins_none_spi = {{DSY_GPIOX, 0}, 255}; +static pin_alt_spi pins_none_spi = {Pin(PORTX, 0), 255}; //this is a bit long... /* ============== spi1 ============== */ -static pin_alt_spi spi1_pins_sclk[] = {{{DSY_GPIOG, 11}, GPIO_AF5_SPI1}, - {{DSY_GPIOA, 5}, GPIO_AF5_SPI1}, +static pin_alt_spi spi1_pins_sclk[] = {{Pin(PORTG, 11), GPIO_AF5_SPI1}, + {Pin(PORTA, 5), GPIO_AF5_SPI1}, pins_none_spi}; -static pin_alt_spi spi1_pins_miso[] = {{{DSY_GPIOB, 4}, GPIO_AF5_SPI1}, - {{DSY_GPIOA, 6}, GPIO_AF5_SPI1}, - {{DSY_GPIOG, 9}, GPIO_AF5_SPI1}}; +static pin_alt_spi spi1_pins_miso[] = {{Pin(PORTB, 4), GPIO_AF5_SPI1}, + {Pin(PORTA, 6), GPIO_AF5_SPI1}, + {Pin(PORTG, 9), GPIO_AF5_SPI1}}; -static pin_alt_spi spi1_pins_mosi[] = {{{DSY_GPIOB, 5}, GPIO_AF5_SPI1}, - {{DSY_GPIOA, 7}, GPIO_AF5_SPI1}, +static pin_alt_spi spi1_pins_mosi[] = {{Pin(PORTB, 5), GPIO_AF5_SPI1}, + {Pin(PORTA, 7), GPIO_AF5_SPI1}, pins_none_spi}; -static pin_alt_spi spi1_pins_nss[] = {{{DSY_GPIOG, 10}, GPIO_AF5_SPI1}, - {{DSY_GPIOA, 4}, GPIO_AF5_SPI1}, +static pin_alt_spi spi1_pins_nss[] = {{Pin(PORTG, 10), GPIO_AF5_SPI1}, + {Pin(PORTA, 4), GPIO_AF5_SPI1}, pins_none_spi}; /* ============== spi2 ============== */ static pin_alt_spi spi2_pins_sclk[] - = {{{DSY_GPIOD, 3}, GPIO_AF5_SPI2}, pins_none_spi, pins_none_spi}; + = {{Pin(PORTD, 3), GPIO_AF5_SPI2}, pins_none_spi, pins_none_spi}; -static pin_alt_spi spi2_pins_miso[] = {{{DSY_GPIOB, 14}, GPIO_AF5_SPI2}, - {{DSY_GPIOC, 2}, GPIO_AF5_SPI2}, +static pin_alt_spi spi2_pins_miso[] = {{Pin(PORTB, 14), GPIO_AF5_SPI2}, + {Pin(PORTC, 2), GPIO_AF5_SPI2}, pins_none_spi}; -static pin_alt_spi spi2_pins_mosi[] = {{{DSY_GPIOC, 1}, GPIO_AF5_SPI2}, - {{DSY_GPIOB, 15}, GPIO_AF5_SPI2}, - {{DSY_GPIOC, 3}, GPIO_AF5_SPI2}}; +static pin_alt_spi spi2_pins_mosi[] = {{Pin(PORTC, 1), GPIO_AF5_SPI2}, + {Pin(PORTB, 15), GPIO_AF5_SPI2}, + {Pin(PORTC, 3), GPIO_AF5_SPI2}}; -static pin_alt_spi spi2_pins_nss[] = {{{DSY_GPIOB, 12}, GPIO_AF5_SPI2}, - {{DSY_GPIOB, 4}, GPIO_AF7_SPI2}, - {{DSY_GPIOB, 9}, GPIO_AF5_SPI2}}; +static pin_alt_spi spi2_pins_nss[] = {{Pin(PORTB, 12), GPIO_AF5_SPI2}, + {Pin(PORTB, 4), GPIO_AF7_SPI2}, + {Pin(PORTB, 9), GPIO_AF5_SPI2}}; /* ============== spi3 ============== */ static pin_alt_spi spi3_pins_sclk[] - = {{{DSY_GPIOC, 10}, GPIO_AF6_SPI3}, pins_none_spi, pins_none_spi}; + = {{Pin(PORTC, 10), GPIO_AF6_SPI3}, pins_none_spi, pins_none_spi}; -static pin_alt_spi spi3_pins_miso[] = {{{DSY_GPIOC, 11}, GPIO_AF6_SPI3}, - {{DSY_GPIOB, 4}, GPIO_AF6_SPI3}, +static pin_alt_spi spi3_pins_miso[] = {{Pin(PORTC, 11), GPIO_AF6_SPI3}, + {Pin(PORTB, 4), GPIO_AF6_SPI3}, pins_none_spi}; -static pin_alt_spi spi3_pins_mosi[] = {{{DSY_GPIOC, 12}, GPIO_AF6_SPI3}, - {{DSY_GPIOB, 5}, GPIO_AF7_SPI3}, +static pin_alt_spi spi3_pins_mosi[] = {{Pin(PORTC, 12), GPIO_AF6_SPI3}, + {Pin(PORTB, 5), GPIO_AF7_SPI3}, pins_none_spi}; static pin_alt_spi spi3_pins_nss[] - = {{{DSY_GPIOA, 4}, GPIO_AF6_SPI3}, pins_none_spi, pins_none_spi}; + = {{Pin(PORTA, 4), GPIO_AF6_SPI3}, pins_none_spi, pins_none_spi}; /* ============== spi4 ============== */ static pin_alt_spi spi4_pins_sclk[] @@ -795,18 +795,18 @@ static pin_alt_spi spi5_pins_nss[] /* ============== spi6 ============== */ static pin_alt_spi spi6_pins_sclk[] - = {{{DSY_GPIOA, 5}, GPIO_AF8_SPI6}, pins_none_spi, pins_none_spi}; + = {{Pin(PORTA, 5), GPIO_AF8_SPI6}, pins_none_spi, pins_none_spi}; -static pin_alt_spi spi6_pins_miso[] = {{{DSY_GPIOB, 4}, GPIO_AF8_SPI6}, - {{DSY_GPIOA, 6}, GPIO_AF8_SPI6}, +static pin_alt_spi spi6_pins_miso[] = {{Pin(PORTB, 4), GPIO_AF8_SPI6}, + {Pin(PORTA, 6), GPIO_AF8_SPI6}, pins_none_spi}; -static pin_alt_spi spi6_pins_mosi[] = {{{DSY_GPIOB, 5}, GPIO_AF8_SPI6}, - {{DSY_GPIOA, 7}, GPIO_AF8_SPI6}, +static pin_alt_spi spi6_pins_mosi[] = {{Pin(PORTB, 5), GPIO_AF8_SPI6}, + {Pin(PORTA, 7), GPIO_AF8_SPI6}, pins_none_spi}; static pin_alt_spi spi6_pins_nss[] - = {{{DSY_GPIOA, 4}, GPIO_AF8_SPI6}, pins_none_spi, pins_none_spi}; + = {{Pin(PORTA, 4), GPIO_AF8_SPI6}, pins_none_spi, pins_none_spi}; //an array to hold everything static pin_alt_spi* pins_periphs_spi[] = { @@ -819,16 +819,16 @@ static pin_alt_spi* pins_periphs_spi[] = { }; SpiHandle::Result -checkPinMatchSpi(GPIO_InitTypeDef* init, dsy_gpio_pin pin, int p_num) +checkPinMatchSpi(GPIO_InitTypeDef* init, Pin pin, int p_num) { for(int i = 0; i < 3; i++) { - if(dsy_pin_cmp(&pins_periphs_spi[p_num][i].pin, &pins_none_spi.pin)) + if(pins_periphs_spi[p_num][i].pin == pins_none_spi.pin) { /* skip */ } - else if(dsy_pin_cmp(&pins_periphs_spi[p_num][i].pin, &pin)) + else if(pins_periphs_spi[p_num][i].pin == pin) { init->Alternate = pins_periphs_spi[p_num][i].alt; return SpiHandle::Result::OK; @@ -886,7 +886,7 @@ SpiHandle::Result SpiHandle::Impl::InitPins() // nss = soft -> ss pin is unused for master and slave bool enable_ss = config_.nss != Config::NSS::SOFT; - if(config_.pin_config.sclk.port != DSY_GPIOX) + if(config_.pin_config.sclk.port != PORTX) { //check sclk against periph if(checkPinMatchSpi(&GPIO_InitStruct, config_.pin_config.sclk, per_num) @@ -896,12 +896,12 @@ SpiHandle::Result SpiHandle::Impl::InitPins() } //setup sclk pin - GPIO_TypeDef* port = dsy_hal_map_get_port(&config_.pin_config.sclk); - GPIO_InitStruct.Pin = dsy_hal_map_get_pin(&config_.pin_config.sclk); + GPIO_TypeDef* port = GetHALPort(config_.pin_config.sclk); + GPIO_InitStruct.Pin = GetHALPin(config_.pin_config.sclk); HAL_GPIO_Init(port, &GPIO_InitStruct); } - if(config_.pin_config.miso.port != DSY_GPIOX && enable_miso) + if(config_.pin_config.miso.port != PORTX && enable_miso) { //check miso against periph if(checkPinMatchSpi( @@ -912,12 +912,12 @@ SpiHandle::Result SpiHandle::Impl::InitPins() } //setup miso pin - GPIO_TypeDef* port = dsy_hal_map_get_port(&config_.pin_config.miso); - GPIO_InitStruct.Pin = dsy_hal_map_get_pin(&config_.pin_config.miso); + GPIO_TypeDef* port = GetHALPort(config_.pin_config.miso); + GPIO_InitStruct.Pin = GetHALPin(config_.pin_config.miso); HAL_GPIO_Init(port, &GPIO_InitStruct); } - if(config_.pin_config.mosi.port != DSY_GPIOX && enable_mosi) + if(config_.pin_config.mosi.port != PORTX && enable_mosi) { //check mosi against periph if(checkPinMatchSpi( @@ -928,12 +928,12 @@ SpiHandle::Result SpiHandle::Impl::InitPins() } //setup mosi pin - GPIO_TypeDef* port = dsy_hal_map_get_port(&config_.pin_config.mosi); - GPIO_InitStruct.Pin = dsy_hal_map_get_pin(&config_.pin_config.mosi); + GPIO_TypeDef* port = GetHALPort(config_.pin_config.mosi); + GPIO_InitStruct.Pin = GetHALPin(config_.pin_config.mosi); HAL_GPIO_Init(port, &GPIO_InitStruct); } - if(config_.pin_config.nss.port != DSY_GPIOX && enable_ss) + if(config_.pin_config.nss.port != PORTX && enable_ss) { //check nss against periph if(checkPinMatchSpi( @@ -944,8 +944,8 @@ SpiHandle::Result SpiHandle::Impl::InitPins() } //setup nss pin - GPIO_TypeDef* port = dsy_hal_map_get_port(&config_.pin_config.nss); - GPIO_InitStruct.Pin = dsy_hal_map_get_pin(&config_.pin_config.nss); + GPIO_TypeDef* port = GetHALPort(config_.pin_config.nss); + GPIO_InitStruct.Pin = GetHALPin(config_.pin_config.nss); HAL_GPIO_Init(port, &GPIO_InitStruct); } @@ -954,20 +954,20 @@ SpiHandle::Result SpiHandle::Impl::InitPins() SpiHandle::Result SpiHandle::Impl::DeInitPins() { - GPIO_TypeDef* port = dsy_hal_map_get_port(&config_.pin_config.sclk); - uint16_t pin = dsy_hal_map_get_pin(&config_.pin_config.sclk); + GPIO_TypeDef* port = GetHALPort(config_.pin_config.sclk); + uint16_t pin = GetHALPin(config_.pin_config.sclk); HAL_GPIO_DeInit(port, pin); - port = dsy_hal_map_get_port(&config_.pin_config.miso); - pin = dsy_hal_map_get_pin(&config_.pin_config.miso); + port = GetHALPort(config_.pin_config.miso); + pin = GetHALPin(config_.pin_config.miso); HAL_GPIO_DeInit(port, pin); - port = dsy_hal_map_get_port(&config_.pin_config.mosi); - pin = dsy_hal_map_get_pin(&config_.pin_config.mosi); + port = GetHALPort(config_.pin_config.mosi); + pin = GetHALPin(config_.pin_config.mosi); HAL_GPIO_DeInit(port, pin); - port = dsy_hal_map_get_port(&config_.pin_config.nss); - pin = dsy_hal_map_get_pin(&config_.pin_config.nss); + port = GetHALPort(config_.pin_config.nss); + pin = GetHALPin(config_.pin_config.nss); HAL_GPIO_DeInit(port, pin); return Result::OK; @@ -985,10 +985,10 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) SpiHandle::Impl* handle = MapInstanceToHandle(spiHandle->Instance); //enable clock on all 4 pins - dsy_hal_map_gpio_clk_enable(handle->config_.pin_config.sclk.port); - dsy_hal_map_gpio_clk_enable(handle->config_.pin_config.miso.port); - dsy_hal_map_gpio_clk_enable(handle->config_.pin_config.mosi.port); - dsy_hal_map_gpio_clk_enable(handle->config_.pin_config.nss.port); + GPIOClockEnable(handle->config_.pin_config.sclk); + GPIOClockEnable(handle->config_.pin_config.miso); + GPIOClockEnable(handle->config_.pin_config.mosi); + GPIOClockEnable(handle->config_.pin_config.nss); //enable clock for our peripheral switch(handle->config_.periph) diff --git a/src/per/spi.h b/src/per/spi.h index 30e4e38c9..92af528a7 100644 --- a/src/per/spi.h +++ b/src/per/spi.h @@ -78,10 +78,10 @@ class SpiHandle struct { - dsy_gpio_pin sclk; /**< & */ - dsy_gpio_pin miso; /**< & */ - dsy_gpio_pin mosi; /**< & */ - dsy_gpio_pin nss; /**< & */ + Pin sclk; /**< & */ + Pin miso; /**< & */ + Pin mosi; /**< & */ + Pin nss; /**< & */ } pin_config; Config() diff --git a/src/per/spiMultislave.cpp b/src/per/spiMultislave.cpp index 5ee217c6d..829ac660c 100644 --- a/src/per/spiMultislave.cpp +++ b/src/per/spiMultislave.cpp @@ -29,7 +29,7 @@ SpiHandle::Result MultiSlaveSpiHandle::Init(const Config& config) spi_config.pin_config.miso = config.pin_config.miso; spi_config.pin_config.mosi = config.pin_config.mosi; spi_config.pin_config.sclk = config.pin_config.sclk; - spi_config.pin_config.nss = {DSY_GPIOX, 0}; // we'll drive this by ourselves + spi_config.pin_config.nss = Pin(PORTX, 0); // we'll drive this by ourselves return spiHandle_.Init(spi_config); } From 5a9d717dbadbaaae8316a9065d8b46787cfb7267 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Mon, 29 May 2023 00:12:47 -0400 Subject: [PATCH 27/38] Update SAI peripheral to use GPIO and Pin --- src/per/sai.cpp | 65 +++++++++++++++++++++++-------------------------- src/per/sai.h | 2 +- 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/per/sai.cpp b/src/per/sai.cpp index bce0bb7e9..8dacf9121 100644 --- a/src/per/sai.cpp +++ b/src/per/sai.cpp @@ -206,10 +206,6 @@ SaiHandle::Result SaiHandle::Impl::Init(const SaiHandle::Config& config) SaiHandle::Result SaiHandle::Impl::DeInit() { - // Must have been initialized before deinitialization - if(&config_ == nullptr) - return Result::ERR; - DeInitDma(PeripheralBlock::BLOCK_A); DeInitDma(PeripheralBlock::BLOCK_B); @@ -234,10 +230,10 @@ void SaiHandle::Impl::InitDma(PeripheralBlock block) hsai = &sai_a_handle_; hdma = &sai_a_dma_handle_; dir = config_.a_dir == Config::Direction::RECEIVE - ? DMA_PERIPH_TO_MEMORY - : DMA_MEMORY_TO_PERIPH; - req = sai_idx == int(Config::Peripheral::SAI_1) ? DMA_REQUEST_SAI1_A - : DMA_REQUEST_SAI2_A; + ? DMA_PERIPH_TO_MEMORY + : DMA_MEMORY_TO_PERIPH; + req = sai_idx == int(Config::Peripheral::SAI_1) ? DMA_REQUEST_SAI1_A + : DMA_REQUEST_SAI2_A; if(sai_idx == int(Config::Peripheral::SAI_1)) hdma->Instance = DMA1_Stream0; @@ -249,10 +245,10 @@ void SaiHandle::Impl::InitDma(PeripheralBlock block) hsai = &sai_b_handle_; hdma = &sai_b_dma_handle_; dir = config_.b_dir == Config::Direction::RECEIVE - ? DMA_PERIPH_TO_MEMORY - : DMA_MEMORY_TO_PERIPH; - req = sai_idx == int(Config::Peripheral::SAI_1) ? DMA_REQUEST_SAI1_B - : DMA_REQUEST_SAI2_B; + ? DMA_PERIPH_TO_MEMORY + : DMA_MEMORY_TO_PERIPH; + req = sai_idx == int(Config::Peripheral::SAI_1) ? DMA_REQUEST_SAI1_B + : DMA_REQUEST_SAI2_B; if(sai_idx == int(Config::Peripheral::SAI_1)) hdma->Instance = DMA1_Stream1; @@ -368,14 +364,14 @@ void SaiHandle::Impl::InitPins() bool is_master; GPIO_InitTypeDef GPIO_InitStruct; GPIO_TypeDef* port; - dsy_gpio_pin* cfg[] = {&config_.pin_config.fs, - &config_.pin_config.mclk, - &config_.pin_config.sck, - &config_.pin_config.sa, - &config_.pin_config.sb}; + Pin cfg[] = {config_.pin_config.fs, + config_.pin_config.mclk, + config_.pin_config.sck, + config_.pin_config.sa, + config_.pin_config.sb}; // Special Case checks - dsy_gpio_pin sck_af_pin = {DSY_GPIOA, 2}; - is_master = (config_.a_sync == Config::Sync::MASTER + Pin sck_af_pin = Pin(PORTA, 2); + is_master = (config_.a_sync == Config::Sync::MASTER || config_.b_sync == Config::Sync::MASTER); // Generics GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; @@ -384,7 +380,7 @@ void SaiHandle::Impl::InitPins() for(size_t i = 0; i < 5; i++) { // Skip MCLK if not master. - if(dsy_pin_cmp(&config_.pin_config.mclk, cfg[i]) && !is_master) + if(config_.pin_config.mclk == cfg[i] && !is_master) continue; // Special case for SAI2-sck (should add a map for Alternate Functions at some point..) @@ -394,15 +390,14 @@ void SaiHandle::Impl::InitPins() GPIO_InitStruct.Alternate = GPIO_AF6_SAI1; break; case Config::Peripheral::SAI_2: - GPIO_InitStruct.Alternate = dsy_pin_cmp(cfg[i], &sck_af_pin) - ? GPIO_AF8_SAI2 - : GPIO_AF10_SAI2; + GPIO_InitStruct.Alternate + = cfg[i] == sck_af_pin ? GPIO_AF8_SAI2 : GPIO_AF10_SAI2; break; default: break; } - GPIO_InitStruct.Pin = dsy_hal_map_get_pin(cfg[i]); - port = dsy_hal_map_get_port(cfg[i]); + GPIO_InitStruct.Pin = GetHALPin(cfg[i]); + port = GetHALPort(cfg[i]); HAL_GPIO_Init(port, &GPIO_InitStruct); } } @@ -416,21 +411,21 @@ void SaiHandle::Impl::DeInitPins() || config_.b_sync == Config::Sync::MASTER); if(is_master) { - port = dsy_hal_map_get_port(&config_.pin_config.mclk); - pin = dsy_hal_map_get_pin(&config_.pin_config.mclk); + port = GetHALPort(config_.pin_config.mclk); + pin = GetHALPin(config_.pin_config.mclk); HAL_GPIO_DeInit(port, pin); } - port = dsy_hal_map_get_port(&config_.pin_config.fs); - pin = dsy_hal_map_get_pin(&config_.pin_config.fs); + port = GetHALPort(config_.pin_config.fs); + pin = GetHALPin(config_.pin_config.fs); HAL_GPIO_DeInit(port, pin); - port = dsy_hal_map_get_port(&config_.pin_config.sck); - pin = dsy_hal_map_get_pin(&config_.pin_config.sck); + port = GetHALPort(config_.pin_config.sck); + pin = GetHALPin(config_.pin_config.sck); HAL_GPIO_DeInit(port, pin); - port = dsy_hal_map_get_port(&config_.pin_config.sa); - pin = dsy_hal_map_get_pin(&config_.pin_config.sa); + port = GetHALPort(config_.pin_config.sa); + pin = GetHALPin(config_.pin_config.sa); HAL_GPIO_DeInit(port, pin); - port = dsy_hal_map_get_port(&config_.pin_config.sb); - pin = dsy_hal_map_get_pin(&config_.pin_config.sb); + port = GetHALPort(config_.pin_config.sb); + pin = GetHALPin(config_.pin_config.sb); HAL_GPIO_DeInit(port, pin); } diff --git a/src/per/sai.h b/src/per/sai.h index bec5c06e9..71258180d 100644 --- a/src/per/sai.h +++ b/src/per/sai.h @@ -90,7 +90,7 @@ class SaiHandle Peripheral periph; struct { - dsy_gpio_pin mclk, fs, sck, sa, sb; + Pin mclk, fs, sck, sa, sb; } pin_config; SampleRate sr; BitDepth bit_depth; From 8b8c9e1d69e8fe65a450415d0282db0a98ab7431 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Mon, 29 May 2023 00:15:06 -0400 Subject: [PATCH 28/38] Update QSPI peripheral to use GPIO and Pin --- src/per/qspi.cpp | 40 +++++++++++++++++++--------------------- src/per/qspi.h | 12 ++++++------ 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/per/qspi.cpp b/src/per/qspi.cpp index 17727910a..30fa0c652 100644 --- a/src/per/qspi.cpp +++ b/src/per/qspi.cpp @@ -4,10 +4,8 @@ #include "stm32h7xx_hal.h" #include "dev/flash_IS25LP080D.h" #include "dev/flash_IS25LP064A.h" -extern "C" -{ #include "util/hal_map.h" -} + // TODO: Add handling for alternate device types, // This will be a thing much sooner than anticipated @@ -93,14 +91,14 @@ class QSPIHandle::Impl Status status_; static constexpr size_t pin_count_ - = sizeof(QSPIHandle::Config::pin_config) / sizeof(dsy_gpio_pin); + = sizeof(QSPIHandle::Config::pin_config) / sizeof(Pin); // Data structure for easy hal initialization - dsy_gpio_pin* pin_config_arr_[pin_count_] = {&config_.pin_config.io0, - &config_.pin_config.io1, - &config_.pin_config.io2, - &config_.pin_config.io3, - &config_.pin_config.clk, - &config_.pin_config.ncs}; + Pin* pin_config_arr_[pin_count_] = {&config_.pin_config.io0, + &config_.pin_config.io1, + &config_.pin_config.io2, + &config_.pin_config.io3, + &config_.pin_config.clk, + &config_.pin_config.ncs}; }; @@ -254,7 +252,7 @@ QSPIHandle::Impl::Write(uint32_t address, uint32_t size, uint8_t* buffer) NumOfPage = size / flash_page_size; NumOfSingle = size % flash_page_size; - if(Addr == 0) /*!< Address is QSPI_PAGESIZE aligned */ + if(Addr == 0) /*!< Address is QSPI_PAGESIZE aligned */ { if(NumOfPage == 0) /*!< NumByteToWrite < QSPI_PAGESIZE */ { @@ -276,7 +274,7 @@ QSPIHandle::Impl::Write(uint32_t address, uint32_t size, uint8_t* buffer) WritePage(address, QSPI_DataNum, buffer, false); } } - else /*!< Address is not QSPI_PAGESIZE aligned */ + else /*!< Address is not QSPI_PAGESIZE aligned */ { if(NumOfPage == 0) /*!< Size < QSPI_PAGESIZE */ { @@ -836,15 +834,15 @@ uint8_t QSPIHandle::Impl::GetStatusRegister() uint32_t QSPIHandle::Impl::GetPin(size_t pin) { - dsy_gpio_pin* p = pin_config_arr_[pin]; - return dsy_hal_map_get_pin(p); + Pin* p = pin_config_arr_[pin]; + return GetHALPin(*p); } GPIO_TypeDef* QSPIHandle::Impl::GetPort(size_t pin) { - dsy_gpio_pin* p = pin_config_arr_[pin]; - return dsy_hal_map_get_port(p); + Pin* p = pin_config_arr_[pin]; + return GetHALPort(*p); } @@ -924,11 +922,11 @@ extern "C" void HAL_QSPI_MspInit(QSPI_HandleTypeDef* qspiHandle) __HAL_RCC_GPIOB_CLK_ENABLE(); // Seems the same for all pin outs so far. uint8_t af_config[qspi_impl.GetNumPins()] = {GPIO_AF10_QUADSPI, - GPIO_AF10_QUADSPI, - GPIO_AF9_QUADSPI, - GPIO_AF9_QUADSPI, - GPIO_AF9_QUADSPI, - GPIO_AF10_QUADSPI}; + GPIO_AF10_QUADSPI, + GPIO_AF9_QUADSPI, + GPIO_AF9_QUADSPI, + GPIO_AF9_QUADSPI, + GPIO_AF10_QUADSPI}; GPIO_TypeDef* port; for(uint8_t i = 0; i < qspi_impl.GetNumPins(); i++) { diff --git a/src/per/qspi.h b/src/per/qspi.h index b1da9efd4..be8ad8b39 100644 --- a/src/per/qspi.h +++ b/src/per/qspi.h @@ -81,12 +81,12 @@ class QSPIHandle //SCK, CE# (active low) struct { - dsy_gpio_pin io0; /**< & */ - dsy_gpio_pin io1; /**< & */ - dsy_gpio_pin io2; /**< & */ - dsy_gpio_pin io3; /**< & */ - dsy_gpio_pin clk; /**< & */ - dsy_gpio_pin ncs; /**< & */ + Pin io0; /**< & */ + Pin io1; /**< & */ + Pin io2; /**< & */ + Pin io3; /**< & */ + Pin clk; /**< & */ + Pin ncs; /**< & */ } pin_config; Device device; From 547a76fa014f4ce684d14833dfbace71f7a4b402 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Mon, 29 May 2023 00:17:57 -0400 Subject: [PATCH 29/38] Update outdated documentation --- src/dev/lcd_hd44780.h | 2 +- src/dev/sr_595.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dev/lcd_hd44780.h b/src/dev/lcd_hd44780.h index e17e5e267..85a4a4d81 100644 --- a/src/dev/lcd_hd44780.h +++ b/src/dev/lcd_hd44780.h @@ -31,7 +31,7 @@ class LcdHD44780 /** Initializes the LCD. - * \param config is a struct that sets cursor on/off, cursor blink on/off and the dsy_gpio_pin's that connects to the LCD. + * \param config is a struct that sets cursor on/off, cursor blink on/off and the Pin's that connects to the LCD. */ void Init(const Config &config); diff --git a/src/dev/sr_595.h b/src/dev/sr_595.h index 81cd9ec6f..2a73d9b75 100644 --- a/src/dev/sr_595.h +++ b/src/dev/sr_595.h @@ -39,7 +39,7 @@ class ShiftRegister595 /** Initializes the GPIO, and data for the ShiftRegister - * \param pin_cfg is an array of dsy_gpio_pin corresponding the the Pins enum above. + * \param pin_cfg is an array of Pin corresponding the the Pins enum above. * \param num_daisy_chained (default = 1) is the number of 595 devices daisy chained together. */ void Init(Pin *pin_cfg, size_t num_daisy_chained = 1); From 783713896168514969d2d3b894c2bb948b12cd09 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Tue, 13 Jun 2023 23:42:39 -0400 Subject: [PATCH 30/38] Style compliance --- src/daisy_patch.h | 12 +++++------ src/daisy_seed.cpp | 4 ++-- src/dev/codec_ak4556.h | 1 + src/dev/lcd_hd44780.cpp | 6 +++--- src/dev/leddriver.h | 6 +++--- src/hid/led.h | 12 +++++------ src/hid/rgb_led.cpp | 5 +---- src/hid/switch.cpp | 2 +- src/hid/switch.h | 8 ++++++-- src/per/adc.cpp | 12 +++++------ src/per/dac.cpp | 36 ++++++++++++++++----------------- src/per/gpio.cpp | 2 +- src/per/i2c.h | 6 +++--- src/per/qspi.cpp | 14 ++++++------- src/per/sai.cpp | 24 +++++++++++----------- src/per/spi.cpp | 3 +-- src/per/uart.cpp | 45 +++++++++-------------------------------- src/per/uart.h | 6 +++--- src/sys/system.cpp | 6 +++--- 19 files changed, 91 insertions(+), 119 deletions(-) diff --git a/src/daisy_patch.h b/src/daisy_patch.h index 15d966775..a3f01d1ab 100644 --- a/src/daisy_patch.h +++ b/src/daisy_patch.h @@ -114,12 +114,12 @@ class DaisyPatch /* These are exposed for the user to access and manipulate directly Helper functions above provide easier access to much of what they are capable of. */ - DaisySeed seed; /**< Seed object */ - Ak4556 codec; /**< Patch's second CODEC */ - Encoder encoder; /**< Encoder object */ - AnalogControl controls[CTRL_LAST]; /**< Array of controls*/ - GateIn gate_input[GATE_IN_LAST]; /**< Gate inputs */ - MidiUartHandler midi; /**< Handles midi*/ + DaisySeed seed; /**< Seed object */ + Ak4556 codec; /**< Patch's second CODEC */ + Encoder encoder; /**< Encoder object */ + AnalogControl controls[CTRL_LAST]; /**< Array of controls*/ + GateIn gate_input[GATE_IN_LAST]; /**< Gate inputs */ + MidiUartHandler midi; /**< Handles midi*/ OledDisplay display; /**< & */ // TODO: Add class for Gate output diff --git a/src/daisy_seed.cpp b/src/daisy_seed.cpp index 10667b04b..02ca561fd 100644 --- a/src/daisy_seed.cpp +++ b/src/daisy_seed.cpp @@ -106,7 +106,7 @@ void DaisySeed::Init(bool boost) led_config.pin = Pin(SEED_LED_PORT, SEED_LED_PIN); led_config.mode = GPIO::Mode::OUTPUT; - testpoint_config.pin = Pin(SEED_TEST_POINT_PORT, SEED_TEST_POINT_PIN); + testpoint_config.pin = Pin(SEED_TEST_POINT_PORT, SEED_TEST_POINT_PIN); testpoint_config.mode = GPIO::Mode::OUTPUT; auto memory = System::GetProgramMemoryRegion(); @@ -235,7 +235,7 @@ void DaisySeed::SetTestPoint(bool state) testpoint.Write(state); } -const SaiHandle& DaisySeed::AudioSaiHandle() const +const SaiHandle &DaisySeed::AudioSaiHandle() const { return sai_1_handle_; } diff --git a/src/dev/codec_ak4556.h b/src/dev/codec_ak4556.h index fcd86f128..ee8b11f29 100644 --- a/src/dev/codec_ak4556.h +++ b/src/dev/codec_ak4556.h @@ -27,6 +27,7 @@ class Ak4556 /** Deinitialization function for Ak4556 ** */ void DeInit(); + private: GPIO reset_; }; diff --git a/src/dev/lcd_hd44780.cpp b/src/dev/lcd_hd44780.cpp index 70720935d..24491f41a 100644 --- a/src/dev/lcd_hd44780.cpp +++ b/src/dev/lcd_hd44780.cpp @@ -32,9 +32,9 @@ Based on: HD44780-Stm32HAL by Olivier Van den Eede (https://github.com/4ilo/HD44 #define OPT_B 0x01 // Turn on cursor blink #define FUNCTION_SET 0x20 -#define OPT_DL 0x10 // Set interface data length -#define OPT_N 0x08 // Set number of display lines -#define OPT_F 0x04 // Set alternate font +#define OPT_DL 0x10 // Set interface data length +#define OPT_N 0x08 // Set number of display lines +#define OPT_F 0x04 // Set alternate font #define SETCGRAM_ADDR 0x040 #define SET_DDRAM_ADDR 0x80 // Set DDRAM address diff --git a/src/dev/leddriver.h b/src/dev/leddriver.h index 8dbd7129d..9c70caeb9 100644 --- a/src/dev/leddriver.h +++ b/src/dev/leddriver.h @@ -64,9 +64,9 @@ class LedDriverPca9685 */ void Init(I2CHandle i2c, const uint8_t (&addresses)[numDrivers], - DmaBuffer dma_buffer_a, - DmaBuffer dma_buffer_b, - Pin oe_pin = Pin(PORTX, 0)) + DmaBuffer dma_buffer_a, + DmaBuffer dma_buffer_b, + Pin oe_pin = Pin(PORTX, 0)) { i2c_ = i2c; draw_buffer_ = dma_buffer_a; diff --git a/src/hid/led.h b/src/hid/led.h index b34597726..543784dd0 100644 --- a/src/hid/led.h +++ b/src/hid/led.h @@ -51,12 +51,12 @@ class Led inline void SetSampleRate(float sample_rate) { samplerate_ = sample_rate; } private: - size_t pwm_cnt_, pwm_thresh_; - float bright_; - float pwm_; - float samplerate_; - bool invert_, on_, off_; - GPIO hw_pin_; + size_t pwm_cnt_, pwm_thresh_; + float bright_; + float pwm_; + float samplerate_; + bool invert_, on_, off_; + GPIO hw_pin_; }; } // namespace daisy diff --git a/src/hid/rgb_led.cpp b/src/hid/rgb_led.cpp index 32a642fcc..88959807e 100644 --- a/src/hid/rgb_led.cpp +++ b/src/hid/rgb_led.cpp @@ -1,9 +1,6 @@ #include "hid/rgb_led.h" using namespace daisy; -void RgbLed::Init(Pin red, - Pin green, - Pin blue, - bool invert) +void RgbLed::Init(Pin red, Pin green, Pin blue, bool invert) { r_.Init(red, invert); g_.Init(green, invert); diff --git a/src/hid/switch.cpp b/src/hid/switch.cpp index 6553edaa7..989d9f5aa 100644 --- a/src/hid/switch.cpp +++ b/src/hid/switch.cpp @@ -38,7 +38,7 @@ void Switch::Debounce() // shift over, and introduce new state. const bool new_val = hw_gpio_.Read(); - state_ = (state_ << 1) | (flip_ ? !new_val : new_val); + state_ = (state_ << 1) | (flip_ ? !new_val : new_val); // Set time at which button was pressed if(state_ == 0x7f) rising_edge_time_ = System::GetNow(); diff --git a/src/hid/switch.h b/src/hid/switch.h index 1ea02d835..d0c14d14a 100644 --- a/src/hid/switch.h +++ b/src/hid/switch.h @@ -41,7 +41,11 @@ class Switch \param pol switch polarity -- Default: POLARITY_INVERTED \param pu switch pull up/down -- Default: PULL_UP */ - void Init(Pin pin, float update_rate, Type t, Polarity pol, GPIO::Pull pu = GPIO::Pull::PULLUP); + void Init(Pin pin, + float update_rate, + Type t, + Polarity pol, + GPIO::Pull pu = GPIO::Pull::PULLUP); /** Simplified Init. @@ -71,7 +75,7 @@ class Switch /** \return true if the button is held down, without debouncing */ inline bool RawState() - { + { const bool raw = hw_gpio_.Read(); return flip_ ? !raw : raw; } diff --git a/src/per/adc.cpp b/src/per/adc.cpp index a7dd6c352..760a17b37 100644 --- a/src/per/adc.cpp +++ b/src/per/adc.cpp @@ -112,7 +112,7 @@ static int get_num_mux_pins_required(int num_mux_ch) return 0; } static void -write_mux_value(uint8_t chn, uint8_t idx, uint8_t num_mux_pins_to_write); + write_mux_value(uint8_t chn, uint8_t idx, uint8_t num_mux_pins_to_write); static const uint32_t adc_channel_from_pin(Pin pin); static const uint32_t adc_channel_from_pin(Pin pin) @@ -339,8 +339,9 @@ void AdcHandle::Init(AdcChannelConfig* cfg, } // init adc channel sequence - sConfig.Channel = adc_channel_from_pin(adc.pin_cfg[i].pin_.GetConfig().pin); - sConfig.Rank = dsy_adc_rank_map[i]; + sConfig.Channel + = adc_channel_from_pin(adc.pin_cfg[i].pin_.GetConfig().pin); + sConfig.Rank = dsy_adc_rank_map[i]; if(HAL_ADC_ConfigChannel(&adc.hadc1, &sConfig) != HAL_OK) { Error_Handler(); @@ -502,10 +503,7 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle) extern "C" { - void DMA1_Stream2_IRQHandler(void) - { - HAL_DMA_IRQHandler(&adc.hdma_adc1); - } + void DMA1_Stream2_IRQHandler(void) { HAL_DMA_IRQHandler(&adc.hdma_adc1); } void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) { diff --git a/src/per/dac.cpp b/src/per/dac.cpp index 012e62059..4b620a62a 100644 --- a/src/per/dac.cpp +++ b/src/per/dac.cpp @@ -17,9 +17,9 @@ class DacHandle::Impl DacHandle::Result Init(const DacHandle::Config &config); const DacHandle::Config &GetConfig() const { return config_; } DacHandle::Result - Start(uint16_t *buffer, size_t size, DacHandle::DacCallback cb); - DacHandle::Result Start(uint16_t *buffer_1, - uint16_t *buffer_2, + Start(uint16_t *buffer, size_t size, DacHandle::DacCallback cb); + DacHandle::Result Start(uint16_t * buffer_1, + uint16_t * buffer_2, size_t size, DacHandle::DacCallback cb); DacHandle::Result Stop(); @@ -45,13 +45,13 @@ class DacHandle::Impl DAC_HandleTypeDef hal_dac_; /**< ST HAL DAC Handle*/ DMA_HandleTypeDef - hal_dac_dma_[2]; /**< ST HAL DMA Hande (one per available channel) */ + hal_dac_dma_[2]; /**< ST HAL DMA Hande (one per available channel) */ TIM_HandleTypeDef hal_tim_; private: DacHandle::Config config_; /**< Config Struct for initialization */ size_t buff_size_; - uint16_t *buff_[2]; + uint16_t * buff_[2]; DacHandle::DacCallback callback_; GPIO d1, d2; }; @@ -110,9 +110,9 @@ DacHandle::Result DacHandle::Impl::Init(const DacHandle::Config &config) // Base tim freq is PClk2 * 2 (200/240MHz depending on system configuration). tim_base_freq = System:: GetPClk2Freq(); // 100MHz (or 120MHz) depending on CPU Freq. - target_freq = config_.target_samplerate == 0 - ? 48000 - : config_.target_samplerate; + target_freq = config_.target_samplerate == 0 + ? 48000 + : config_.target_samplerate; period = tim_base_freq / target_freq; hal_tim_.Init.Period = period; hal_tim_.Init.Prescaler = 1; @@ -159,11 +159,11 @@ DacHandle::Impl::Start(uint16_t *buffer, size_t size, DacHandle::DacCallback cb) { if(config_.mode != Mode::DMA || config_.chn == Channel::BOTH) return Result::ERR; - callback_ = cb; - buff_[0] = buffer; - buff_size_ = size; - uint32_t bd = config_.bitdepth == BitDepth::BITS_8 ? DAC_ALIGN_8B_R - : DAC_ALIGN_12B_R; + callback_ = cb; + buff_[0] = buffer; + buff_size_ = size; + uint32_t bd = config_.bitdepth == BitDepth::BITS_8 ? DAC_ALIGN_8B_R + : DAC_ALIGN_12B_R; uint32_t chn = config_.chn == Channel::ONE ? DAC_CHANNEL_1 : DAC_CHANNEL_2; HAL_DAC_Start_DMA(&hal_dac_, chn, (uint32_t *)buff_[0], size, bd); HAL_TIM_Base_Start(&hal_tim_); @@ -172,8 +172,8 @@ DacHandle::Impl::Start(uint16_t *buffer, size_t size, DacHandle::DacCallback cb) /** Not fully implemented -- I had the intention of setting up both DACs to work from a single callback, which ** it seems like will require a bit more setup in the Init (basically set it to dual mode). */ -DacHandle::Result DacHandle::Impl::Start(uint16_t *buffer_1, - uint16_t *buffer_2, +DacHandle::Result DacHandle::Impl::Start(uint16_t * buffer_1, + uint16_t * buffer_2, size_t size, DacHandle::DacCallback cb) { @@ -189,7 +189,7 @@ DacHandle::Result DacHandle::Impl::Start(uint16_t *buffer_1, buff_[1] = buffer_2; buff_size_ = size; bd = config_.bitdepth == BitDepth::BITS_8 ? DAC_ALIGN_8B_R - : DAC_ALIGN_12B_R; + : DAC_ALIGN_12B_R; // Start the DACs and then start the time source. HAL_DAC_Start_DMA(&hal_dac_, DAC_CHANNEL_1, (uint32_t *)buff_[0], size, bd); @@ -444,8 +444,8 @@ DacHandle::Start(uint16_t *buffer, size_t size, DacHandle::DacCallback cb) return pimpl_->Start(buffer, size, cb); } -DacHandle::Result DacHandle::Start(uint16_t *buffer_1, - uint16_t *buffer_2, +DacHandle::Result DacHandle::Start(uint16_t * buffer_1, + uint16_t * buffer_2, size_t size, DacHandle::DacCallback cb) { diff --git a/src/per/gpio.cpp b/src/per/gpio.cpp index f865259a6..4b8f0f02f 100644 --- a/src/per/gpio.cpp +++ b/src/per/gpio.cpp @@ -147,7 +147,7 @@ extern "C" void dsy_gpio_init(const dsy_gpio *p) { - GPIO_TypeDef *port; + GPIO_TypeDef * port; GPIO_InitTypeDef ginit; switch(p->mode) { diff --git a/src/per/i2c.h b/src/per/i2c.h index 4635c2229..140a82fd0 100644 --- a/src/per/i2c.h +++ b/src/per/i2c.h @@ -56,9 +56,9 @@ class I2CHandle Peripheral periph; /**< & */ struct { - Pin scl; /**< & */ - Pin sda; /**< & */ - } pin_config; /**< & */ + Pin scl; /**< & */ + Pin sda; /**< & */ + } pin_config; /**< & */ Speed speed; /**< & */ Mode mode; /**< & */ diff --git a/src/per/qspi.cpp b/src/per/qspi.cpp index 30fa0c652..ab268d9e6 100644 --- a/src/per/qspi.cpp +++ b/src/per/qspi.cpp @@ -252,7 +252,7 @@ QSPIHandle::Impl::Write(uint32_t address, uint32_t size, uint8_t* buffer) NumOfPage = size / flash_page_size; NumOfSingle = size % flash_page_size; - if(Addr == 0) /*!< Address is QSPI_PAGESIZE aligned */ + if(Addr == 0) /*!< Address is QSPI_PAGESIZE aligned */ { if(NumOfPage == 0) /*!< NumByteToWrite < QSPI_PAGESIZE */ { @@ -274,7 +274,7 @@ QSPIHandle::Impl::Write(uint32_t address, uint32_t size, uint8_t* buffer) WritePage(address, QSPI_DataNum, buffer, false); } } - else /*!< Address is not QSPI_PAGESIZE aligned */ + else /*!< Address is not QSPI_PAGESIZE aligned */ { if(NumOfPage == 0) /*!< Size < QSPI_PAGESIZE */ { @@ -922,11 +922,11 @@ extern "C" void HAL_QSPI_MspInit(QSPI_HandleTypeDef* qspiHandle) __HAL_RCC_GPIOB_CLK_ENABLE(); // Seems the same for all pin outs so far. uint8_t af_config[qspi_impl.GetNumPins()] = {GPIO_AF10_QUADSPI, - GPIO_AF10_QUADSPI, - GPIO_AF9_QUADSPI, - GPIO_AF9_QUADSPI, - GPIO_AF9_QUADSPI, - GPIO_AF10_QUADSPI}; + GPIO_AF10_QUADSPI, + GPIO_AF9_QUADSPI, + GPIO_AF9_QUADSPI, + GPIO_AF9_QUADSPI, + GPIO_AF10_QUADSPI}; GPIO_TypeDef* port; for(uint8_t i = 0; i < qspi_impl.GetNumPins(); i++) { diff --git a/src/per/sai.cpp b/src/per/sai.cpp index 8dacf9121..2014c8a15 100644 --- a/src/per/sai.cpp +++ b/src/per/sai.cpp @@ -230,10 +230,10 @@ void SaiHandle::Impl::InitDma(PeripheralBlock block) hsai = &sai_a_handle_; hdma = &sai_a_dma_handle_; dir = config_.a_dir == Config::Direction::RECEIVE - ? DMA_PERIPH_TO_MEMORY - : DMA_MEMORY_TO_PERIPH; - req = sai_idx == int(Config::Peripheral::SAI_1) ? DMA_REQUEST_SAI1_A - : DMA_REQUEST_SAI2_A; + ? DMA_PERIPH_TO_MEMORY + : DMA_MEMORY_TO_PERIPH; + req = sai_idx == int(Config::Peripheral::SAI_1) ? DMA_REQUEST_SAI1_A + : DMA_REQUEST_SAI2_A; if(sai_idx == int(Config::Peripheral::SAI_1)) hdma->Instance = DMA1_Stream0; @@ -245,10 +245,10 @@ void SaiHandle::Impl::InitDma(PeripheralBlock block) hsai = &sai_b_handle_; hdma = &sai_b_dma_handle_; dir = config_.b_dir == Config::Direction::RECEIVE - ? DMA_PERIPH_TO_MEMORY - : DMA_MEMORY_TO_PERIPH; - req = sai_idx == int(Config::Peripheral::SAI_1) ? DMA_REQUEST_SAI1_B - : DMA_REQUEST_SAI2_B; + ? DMA_PERIPH_TO_MEMORY + : DMA_MEMORY_TO_PERIPH; + req = sai_idx == int(Config::Peripheral::SAI_1) ? DMA_REQUEST_SAI1_B + : DMA_REQUEST_SAI2_B; if(sai_idx == int(Config::Peripheral::SAI_1)) hdma->Instance = DMA1_Stream1; @@ -365,10 +365,10 @@ void SaiHandle::Impl::InitPins() GPIO_InitTypeDef GPIO_InitStruct; GPIO_TypeDef* port; Pin cfg[] = {config_.pin_config.fs, - config_.pin_config.mclk, - config_.pin_config.sck, - config_.pin_config.sa, - config_.pin_config.sb}; + config_.pin_config.mclk, + config_.pin_config.sck, + config_.pin_config.sa, + config_.pin_config.sb}; // Special Case checks Pin sck_af_pin = Pin(PORTA, 2); is_master = (config_.a_sync == Config::Sync::MASTER diff --git a/src/per/spi.cpp b/src/per/spi.cpp index bac197c7a..e913d4c98 100644 --- a/src/per/spi.cpp +++ b/src/per/spi.cpp @@ -818,8 +818,7 @@ static pin_alt_spi* pins_periphs_spi[] = { spi6_pins_sclk, spi6_pins_miso, spi6_pins_mosi, spi6_pins_nss, }; -SpiHandle::Result -checkPinMatchSpi(GPIO_InitTypeDef* init, Pin pin, int p_num) +SpiHandle::Result checkPinMatchSpi(GPIO_InitTypeDef* init, Pin pin, int p_num) { for(int i = 0; i < 3; i++) { diff --git a/src/per/uart.cpp b/src/per/uart.cpp index 13194a530..f5c734969 100644 --- a/src/per/uart.cpp +++ b/src/per/uart.cpp @@ -964,42 +964,15 @@ void UART_IRQHandler(UartHandler::Impl* handle) extern "C" { - void USART1_IRQHandler() - { - UART_IRQHandler(&uart_handles[0]); - } - void USART2_IRQHandler() - { - UART_IRQHandler(&uart_handles[1]); - } - void USART3_IRQHandler() - { - UART_IRQHandler(&uart_handles[2]); - } - void UART4_IRQHandler() - { - UART_IRQHandler(&uart_handles[3]); - } - void UART5_IRQHandler() - { - UART_IRQHandler(&uart_handles[4]); - } - void USART6_IRQHandler() - { - UART_IRQHandler(&uart_handles[5]); - } - void UART7_IRQHandler() - { - UART_IRQHandler(&uart_handles[6]); - } - void UART8_IRQHandler() - { - UART_IRQHandler(&uart_handles[7]); - } - void LPUART1_IRQHandler() - { - UART_IRQHandler(&uart_handles[8]); - } + void USART1_IRQHandler() { UART_IRQHandler(&uart_handles[0]); } + void USART2_IRQHandler() { UART_IRQHandler(&uart_handles[1]); } + void USART3_IRQHandler() { UART_IRQHandler(&uart_handles[2]); } + void UART4_IRQHandler() { UART_IRQHandler(&uart_handles[3]); } + void UART5_IRQHandler() { UART_IRQHandler(&uart_handles[4]); } + void USART6_IRQHandler() { UART_IRQHandler(&uart_handles[5]); } + void UART7_IRQHandler() { UART_IRQHandler(&uart_handles[6]); } + void UART8_IRQHandler() { UART_IRQHandler(&uart_handles[7]); } + void LPUART1_IRQHandler() { UART_IRQHandler(&uart_handles[8]); } } void HalUartDmaRxStreamCallback(void) diff --git a/src/per/uart.h b/src/per/uart.h index 75baa6fc9..3daf06130 100644 --- a/src/per/uart.h +++ b/src/per/uart.h @@ -71,9 +71,9 @@ class UartHandler struct { - Pin tx; /**< & */ - Pin rx; /**< & */ - } pin_config; /**< & */ + Pin tx; /**< & */ + Pin rx; /**< & */ + } pin_config; /**< & */ Config() { diff --git a/src/sys/system.cpp b/src/sys/system.cpp index 1444e85da..ad1a74484 100644 --- a/src/sys/system.cpp +++ b/src/sys/system.cpp @@ -413,9 +413,9 @@ void System::ConfigureClocks() // New Timing PeriphClkInitStruct.PLL2.PLL2N = 12; // Max supported freq of FMC; PeriphClkInitStruct.PLL2.PLL2M = 1; - PeriphClkInitStruct.PLL2.PLL2P = 8; // 25MHz - PeriphClkInitStruct.PLL2.PLL2Q = 2; // 100MHz - PeriphClkInitStruct.PLL2.PLL2R = 1; // 200MHz + PeriphClkInitStruct.PLL2.PLL2P = 8; // 25MHz + PeriphClkInitStruct.PLL2.PLL2Q = 2; // 100MHz + PeriphClkInitStruct.PLL2.PLL2R = 1; // 200MHz PeriphClkInitStruct.PLL2.PLL2FRACN = 4096; From 0f4bbe07861349735b0d22afa0f9f8ac0d1278c8 Mon Sep 17 00:00:00 2001 From: Katherine Whitlock Date: Wed, 21 Feb 2024 15:15:10 -0500 Subject: [PATCH 31/38] Fix ResetToBootloader (merge error) --- src/sys/system.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/system.cpp b/src/sys/system.cpp index 5c38027df..6f3ca335a 100644 --- a/src/sys/system.cpp +++ b/src/sys/system.cpp @@ -298,7 +298,7 @@ void System::DelayTicks(uint32_t delay_ticks) tim_.DelayTick(delay_ticks); } -void System::ResetToBootloader() +void System::ResetToBootloader(BootloaderMode mode) { if(mode == BootloaderMode::STM) { From 71a56b4c03320fb899686763df2e066bed9614ef Mon Sep 17 00:00:00 2001 From: beserge Date: Mon, 26 Feb 2024 13:06:04 -0500 Subject: [PATCH 32/38] Replace old dsy_gpio in DaisySeed with modern GPIO --- src/daisy_seed.cpp | 65 +++++++++++++++++++--------------------------- src/daisy_seed.h | 2 +- 2 files changed, 28 insertions(+), 39 deletions(-) diff --git a/src/daisy_seed.cpp b/src/daisy_seed.cpp index 35d99dd1f..09b27dc89 100644 --- a/src/daisy_seed.cpp +++ b/src/daisy_seed.cpp @@ -9,9 +9,9 @@ constexpr GPIOPort SEED_TEST_POINT_PORT = PORTG; constexpr uint8_t SEED_TEST_POINT_PIN = 14; #ifndef SEED_REV2 -const dsy_gpio_pin seedgpio[33] = { +const Pin seedgpio[33] = { // GPIO 1-8 - //{DSY_GPIOA, 8}, // removed on Rev4 + //{PORTA, 8}, // removed on Rev4 Pin(PORTB, 12), Pin(PORTC, 11), Pin(PORTC, 10), @@ -52,12 +52,10 @@ const dsy_gpio_pin seedgpio[33] = { Pin(PORTC, 3), }; #else -const dsy_gpio_port seed_ports[32] = { - DSY_GPIOA, DSY_GPIOB, DSY_GPIOC, DSY_GPIOC, DSY_GPIOC, DSY_GPIOC, DSY_GPIOD, - DSY_GPIOC, DSY_GPIOG, DSY_GPIOG, DSY_GPIOB, DSY_GPIOB, DSY_GPIOB, DSY_GPIOB, - DSY_GPIOB, DSY_GPIOB, DSY_GPIOC, DSY_GPIOA, DSY_GPIOA, DSY_GPIOB, DSY_GPIOA, - DSY_GPIOA, DSY_GPIOC, DSY_GPIOC, DSY_GPIOA, DSY_GPIOA, DSY_GPIOA, DSY_GPIOD, - DSY_GPIOG, DSY_GPIOA, DSY_GPIOB, DSY_GPIOB, +const GPIOPort seed_ports[32] = { + PORTA, PORTB, PORTC, PORTC, PORTC, PORTC, PORTD, PORTC, PORTG, PORTG, PORTB, + PORTB, PORTB, PORTB, PORTB, PORTB, PORTC, PORTA, PORTA, PORTB, PORTA, PORTA, + PORTC, PORTC, PORTA, PORTA, PORTA, PORTD, PORTG, PORTA, PORTB, PORTB, }; const uint8_t seed_pins[32] = { @@ -65,23 +63,23 @@ const uint8_t seed_pins[32] = { 0, 1, 3, 1, 7, 6, 1, 5, 5, 4, 0, 11, 9, 2, 14, 15, }; -const dsy_gpio_pin seedgpio[32] = { - {seed_ports[0], seed_pins[0]}, {seed_ports[1], seed_pins[1]}, - {seed_ports[2], seed_pins[2]}, {seed_ports[3], seed_pins[3]}, - {seed_ports[4], seed_pins[4]}, {seed_ports[5], seed_pins[5]}, - {seed_ports[6], seed_pins[6]}, {seed_ports[7], seed_pins[7]}, - {seed_ports[8], seed_pins[8]}, {seed_ports[9], seed_pins[9]}, - {seed_ports[10], seed_pins[10]}, {seed_ports[11], seed_pins[11]}, - {seed_ports[12], seed_pins[12]}, {seed_ports[13], seed_pins[13]}, - {seed_ports[14], seed_pins[14]}, {seed_ports[15], seed_pins[15]}, - {seed_ports[16], seed_pins[16]}, {seed_ports[17], seed_pins[17]}, - {seed_ports[18], seed_pins[18]}, {seed_ports[19], seed_pins[19]}, - {seed_ports[20], seed_pins[20]}, {seed_ports[21], seed_pins[21]}, - {seed_ports[22], seed_pins[22]}, {seed_ports[23], seed_pins[23]}, - {seed_ports[24], seed_pins[24]}, {seed_ports[25], seed_pins[25]}, - {seed_ports[26], seed_pins[26]}, {seed_ports[27], seed_pins[27]}, - {seed_ports[28], seed_pins[28]}, {seed_ports[29], seed_pins[29]}, - {seed_ports[30], seed_pins[30]}, {seed_ports[31], seed_pins[31]}, +const Pin seedgpio[32] = { + Pin(seed_ports[0], seed_pins[0]), Pin(seed_ports[1], seed_pins[1]), + Pin(seed_ports[2], seed_pins[2]), Pin(seed_ports[3], seed_pins[3]), + Pin(seed_ports[4], seed_pins[4]), Pin(seed_ports[5], seed_pins[5]), + Pin(seed_ports[6], seed_pins[6]), Pin(seed_ports[7], seed_pins[7]), + Pin(seed_ports[8], seed_pins[8]), Pin(seed_ports[9], seed_pins[9]), + Pin(seed_ports[10], seed_pins[10]), Pin(seed_ports[11], seed_pins[11]), + Pin(seed_ports[12], seed_pins[12]), Pin(seed_ports[13], seed_pins[13]), + Pin(seed_ports[14], seed_pins[14]), Pin(seed_ports[15], seed_pins[15]), + Pin(seed_ports[16], seed_pins[16]), Pin(seed_ports[17], seed_pins[17]), + Pin(seed_ports[18], seed_pins[18]), Pin(seed_ports[19], seed_pins[19]), + Pin(seed_ports[20], seed_pins[20]), Pin(seed_ports[21], seed_pins[21]), + Pin(seed_ports[22], seed_pins[22]), Pin(seed_ports[23], seed_pins[23]), + Pin(seed_ports[24], seed_pins[24]), Pin(seed_ports[25], seed_pins[25]), + Pin(seed_ports[26], seed_pins[26]), Pin(seed_ports[27], seed_pins[27]), + Pin(seed_ports[28], seed_pins[28]), Pin(seed_ports[29], seed_pins[29]), + Pin(seed_ports[30], seed_pins[30]), Pin(seed_ports[31], seed_pins[31]), }; #endif @@ -147,30 +145,21 @@ void DaisySeed::DeInit() // This is intended to be used by the bootloader, but // we don't want to reinitialize pretty much anything in the // target application, so... - // qspi.DeInit(); - // sdram_handle.DeInit(); - // dsy_gpio_deinit(&led); - // dsy_gpio_deinit(&testpoint); - - // dsy_gpio_pin codec_reset_pin; - // codec_reset_pin = {DSY_GPIOB, 11}; - // // Perhaps a bit unnecessary, but maybe we'll make - // // this non-static at some point - // Ak4556::DeInit(codec_reset_pin); - // audio_handle.DeInit(); system.DeInit(); } -dsy_gpio_pin DaisySeed::GetPin(uint8_t pin_idx) +Pin DaisySeed::GetPin(uint8_t pin_idx) { - dsy_gpio_pin p; + Pin p; pin_idx = pin_idx < sizeof(seedgpio) / sizeof(seedgpio[0]) ? pin_idx : 0; + #ifndef SEED_REV2 p = seedgpio[pin_idx]; #else p = {seed_ports[pin_idx], seed_pins[pin_idx]}; #endif + return p; } diff --git a/src/daisy_seed.h b/src/daisy_seed.h index 86b72a14f..af449ce26 100644 --- a/src/daisy_seed.h +++ b/src/daisy_seed.h @@ -52,7 +52,7 @@ class DaisySeed Returns the gpio_pin corresponding to the index 0-31. For the given GPIO on the Daisy Seed (labeled 1-32 in docs). */ - static dsy_gpio_pin GetPin(uint8_t pin_idx); + static Pin GetPin(uint8_t pin_idx); /** Begins the audio for the seeds builtin audio. the specified callback will get called whenever From ba8248df7aeadd946aee541c0e8d96f8c6c7333f Mon Sep 17 00:00:00 2001 From: beserge Date: Mon, 26 Feb 2024 13:11:44 -0500 Subject: [PATCH 33/38] Move patch_sm to modern GPIO --- src/daisy_patch_sm.cpp | 2 +- src/daisy_patch_sm.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/daisy_patch_sm.cpp b/src/daisy_patch_sm.cpp index 53f92f239..d4fba01f7 100644 --- a/src/daisy_patch_sm.cpp +++ b/src/daisy_patch_sm.cpp @@ -443,7 +443,7 @@ namespace patch_sm float DaisyPatchSM::GetAdcValue(int idx) { return controls[idx].Value(); } - dsy_gpio_pin DaisyPatchSM::GetPin(const PinBank bank, const int idx) + Pin DaisyPatchSM::GetPin(const PinBank bank, const int idx) { if(idx <= 0 || idx > 10) return DUMMYPIN; diff --git a/src/daisy_patch_sm.h b/src/daisy_patch_sm.h index ee1986608..e9a5548a2 100644 --- a/src/daisy_patch_sm.h +++ b/src/daisy_patch_sm.h @@ -143,7 +143,7 @@ namespace patch_sm * \param idx pin number between 1 and 10 for each of the pins on each header. * \deprecated please use the Pin definitions in daisy::patch_sm instead */ - dsy_gpio_pin GetPin(const PinBank bank, const int idx); + Pin GetPin(const PinBank bank, const int idx); /** Starts the DAC for the CV Outputs * From 25a0b1c73b2426e9214d1f5ad1e697ba8f77ca81 Mon Sep 17 00:00:00 2001 From: beserge Date: Mon, 26 Feb 2024 14:13:07 -0500 Subject: [PATCH 34/38] Rip up all old GPIO usage --- src/daisy_core.h | 80 ------------------------------------- src/daisy_patch_sm.cpp | 1 - src/dev/sdram.cpp | 4 -- src/hid/gatein.cpp | 11 ------ src/hid/gatein.h | 15 ------- src/hid/led.cpp | 7 ---- src/per/adc.cpp | 1 - src/per/dac.cpp | 5 --- src/per/dac.h | 2 +- src/per/gpio.cpp | 90 ------------------------------------------ src/per/gpio.h | 72 --------------------------------- src/per/i2c.cpp | 1 - src/per/i2c.h | 1 + src/per/qspi.cpp | 2 - src/per/qspi.h | 3 +- src/per/rng.cpp | 2 +- src/per/sai.cpp | 4 -- src/per/sai.h | 1 + src/per/sdmmc.cpp | 3 -- src/per/sdmmc.h | 2 +- src/per/spi.cpp | 6 --- src/per/spi.h | 1 + src/per/tim.cpp | 1 - src/per/tim.h | 1 + src/per/uart.cpp | 5 --- src/per/uart.h | 2 +- src/util/hal_map.c | 74 ---------------------------------- src/util/hal_map.h | 28 ------------- 28 files changed, 10 insertions(+), 415 deletions(-) delete mode 100644 src/util/hal_map.c diff --git a/src/daisy_core.h b/src/daisy_core.h index c0bfe3cdc..fcf0f2685 100644 --- a/src/daisy_core.h +++ b/src/daisy_core.h @@ -167,74 +167,6 @@ FORCE_INLINE int32_t f2s32(float x) return (int32_t)(x * F2S32_SCALE); } - -/** Enums and a simple struct for defining a hardware pin on the MCU - * These correlate with the stm32 datasheet, and are used to configure - * the hardware. - * - * This along with the dsy_gpio_pin class should no longer be used. - * They are available for backwards compatability. - * - * Please use GPIOPort enum and the Pin struct instead. - */ -typedef enum -{ - DSY_GPIOA, /**< & */ - DSY_GPIOB, /**< & */ - DSY_GPIOC, /**< & */ - DSY_GPIOD, /**< & */ - DSY_GPIOE, /**< & */ - DSY_GPIOF, /**< & */ - DSY_GPIOG, /**< & */ - DSY_GPIOH, /**< & */ - DSY_GPIOI, /**< & */ - DSY_GPIOJ, /**< & */ - DSY_GPIOK, /**< & */ - DSY_GPIOX, /** This is a non-existant port for unsupported bits of hardware. */ - DSY_GPIO_LAST, /** Final enum member */ -} dsy_gpio_port; - -/** Hardware define pins - * - * The dsy_gpio_pin struct should no longer be used, and is only available for - * backwards compatability. - * - * Please use Pin struct instead. - */ -typedef struct -{ - dsy_gpio_port port; /**< & */ - uint8_t pin; /**< number 0-15 */ -} dsy_gpio_pin; - -/** Helper for creating pins from port/pin combos easily - * - * The dsy_gpio_pin struct should no longer be used, and is only available for - * backwards compatability. - * - * Please use Pin struct instead. -*/ -FORCE_INLINE dsy_gpio_pin dsy_pin(dsy_gpio_port port, uint8_t pin) -{ - dsy_gpio_pin p; - p.port = port; - p.pin = pin; - return p; -} - -/** Helper for testing sameness of two dsy_gpio_pins - * \return 1 if same, 0 if different - * - * The dsy_gpio_pin struct should no longer be used, and is only available for - * backwards compatability. - * - * Please use Pin struct instead. - */ -FORCE_INLINE uint8_t dsy_pin_cmp(dsy_gpio_pin *a, dsy_gpio_pin *b) -{ - return ((a->port == b->port) && (a->pin == b->pin)); -} - #ifdef __cplusplus namespace daisy @@ -284,18 +216,6 @@ struct Pin /** @brief comparison operator for checking inequality between Pin objects */ constexpr bool operator!=(const Pin &rhs) const { return !operator==(rhs); } - - /** @brief conversion operation for converting to the old-style representation - * of a pin. - * - * This allows the new Pin type to be used in place of the older, dsy_gpio_pin - * type. - */ - constexpr operator dsy_gpio_pin() const - { - return dsy_gpio_pin{.port = static_cast(port), - .pin = pin}; - } }; } // namespace daisy diff --git a/src/daisy_patch_sm.cpp b/src/daisy_patch_sm.cpp index d4fba01f7..6ca02b711 100644 --- a/src/daisy_patch_sm.cpp +++ b/src/daisy_patch_sm.cpp @@ -331,7 +331,6 @@ namespace patch_sm /** Fixed-function Digital I/O */ user_led.Init(PIN_USER_LED, GPIO::Mode::OUTPUT); - //gate_in_1.Init((dsy_gpio_pin *)&DaisyPatchSM::B10); gate_in_1.Init(B10); gate_in_2.Init(B9); diff --git a/src/dev/sdram.cpp b/src/dev/sdram.cpp index 366aab3df..47ca64f63 100644 --- a/src/dev/sdram.cpp +++ b/src/dev/sdram.cpp @@ -1,9 +1,5 @@ #include #include "dev/sdram.h" -extern "C" -{ -#include "util/hal_map.h" -} // TODO: // - Consider alternative to libdaisy.h inclusion for board specific details. diff --git a/src/hid/gatein.cpp b/src/hid/gatein.cpp index c405791a9..76a98dea9 100644 --- a/src/hid/gatein.cpp +++ b/src/hid/gatein.cpp @@ -2,17 +2,6 @@ using namespace daisy; -void GateIn::Init(dsy_gpio_pin *pin_cfg, bool invert) -{ - /** Converting old type to new type */ - Pin p(static_cast(pin_cfg->port), pin_cfg->pin); - pin_.Init(p, GPIO::Mode::INPUT); - prev_state_ = false; - state_ = false; - invert_ = invert; -} - - void GateIn::Init(Pin pin_cfg, bool invert) { pin_.Init(pin_cfg, GPIO::Mode::INPUT); diff --git a/src/hid/gatein.h b/src/hid/gatein.h index f390930f8..40608ebb1 100644 --- a/src/hid/gatein.h +++ b/src/hid/gatein.h @@ -31,21 +31,6 @@ class GateIn */ void Init(Pin pin, bool invert = true); - /** @brief Initializes the gate input with specified hardware pin - * - * @param pin_cfg pointer to pin to initialize - * @param invert True if the pin state is HIGH when 0V is present - * at the input. False if input signal matches the pin state. - * - * @note the default for invert is true because it is typical to use - * an inverting input circuit (e.g. a BJT circuit) for eurorack gate inputs. - * - * @note deprectated - this function still works, but will eventually be removed. - * It uses the old style dsy_gpio_pin in a way that it is not compatible with the - * the new Pin class. - */ - void Init(dsy_gpio_pin *pin_cfg, bool invert = true); - /** Checks current state of gate input. * @return True if the GPIO just transitioned. */ diff --git a/src/hid/led.cpp b/src/hid/led.cpp index 68f94a9c9..6a3b28e3a 100644 --- a/src/hid/led.cpp +++ b/src/hid/led.cpp @@ -40,11 +40,4 @@ void Led::Update() if(pwm_ > 1.f) pwm_ -= 1.f; hw_pin_.Write(bright_ > pwm_ ? on_ : off_); - - // Once we have a slower timer set up: - // Right now its too fast. - - // dsy_gpio_write(&hw_pin_, - // (dsy_tim_get_tick() & RESOLUTION_MAX) < pwm_thresh_ ? on_ - // : off_); } diff --git a/src/per/adc.cpp b/src/per/adc.cpp index b37008461..a1f6bdd98 100644 --- a/src/per/adc.cpp +++ b/src/per/adc.cpp @@ -1,6 +1,5 @@ #include #include "per/adc.h" -#include "util/hal_map.h" using namespace daisy; diff --git a/src/per/dac.cpp b/src/per/dac.cpp index 4b620a62a..0a876d29c 100644 --- a/src/per/dac.cpp +++ b/src/per/dac.cpp @@ -3,11 +3,6 @@ #include "per/tim.h" #include "per/dac.h" -extern "C" -{ -#include "util/hal_map.h" -} - namespace daisy { /** Private Implementation class */ diff --git a/src/per/dac.h b/src/per/dac.h index 01db93d51..60677fa2e 100644 --- a/src/per/dac.h +++ b/src/per/dac.h @@ -1,7 +1,7 @@ #pragma once #ifndef DSY_DAC_H #define DSY_DAC_H - +#include "stm32h7xx_hal.h" #include "daisy_core.h" namespace daisy diff --git a/src/per/gpio.cpp b/src/per/gpio.cpp index 5831b4eb0..47f1785bb 100644 --- a/src/per/gpio.cpp +++ b/src/per/gpio.cpp @@ -119,93 +119,3 @@ uint32_t *GPIO::GetGPIOBaseRegister() default: return NULL; } } - -// #include "stm32h7xx_hal.h" -// #include "per/gpio.h" - -/** OLD C Stuff */ -extern "C" -{ -#include "util/hal_map.h" - - static void start_clock_for_pin(const dsy_gpio *p) - { - switch(p->pin.port) - { - case DSY_GPIOA: __HAL_RCC_GPIOA_CLK_ENABLE(); break; - case DSY_GPIOB: __HAL_RCC_GPIOB_CLK_ENABLE(); break; - case DSY_GPIOC: __HAL_RCC_GPIOC_CLK_ENABLE(); break; - case DSY_GPIOD: __HAL_RCC_GPIOD_CLK_ENABLE(); break; - case DSY_GPIOE: __HAL_RCC_GPIOE_CLK_ENABLE(); break; - case DSY_GPIOF: __HAL_RCC_GPIOF_CLK_ENABLE(); break; - case DSY_GPIOG: __HAL_RCC_GPIOG_CLK_ENABLE(); break; - case DSY_GPIOH: __HAL_RCC_GPIOH_CLK_ENABLE(); break; - case DSY_GPIOI: __HAL_RCC_GPIOI_CLK_ENABLE(); break; - default: break; - } - } - - void dsy_gpio_init(const dsy_gpio *p) - { - GPIO_TypeDef * port; - GPIO_InitTypeDef ginit; - switch(p->mode) - { - case DSY_GPIO_MODE_INPUT: ginit.Mode = GPIO_MODE_INPUT; break; - case DSY_GPIO_MODE_OUTPUT_PP: - ginit.Mode = GPIO_MODE_OUTPUT_PP; - break; - case DSY_GPIO_MODE_OUTPUT_OD: - ginit.Mode = GPIO_MODE_OUTPUT_OD; - break; - case DSY_GPIO_MODE_ANALOG: ginit.Mode = GPIO_MODE_ANALOG; break; - default: ginit.Mode = GPIO_MODE_INPUT; break; - } - switch(p->pull) - { - case DSY_GPIO_NOPULL: ginit.Pull = GPIO_NOPULL; break; - case DSY_GPIO_PULLUP: ginit.Pull = GPIO_PULLUP; break; - case DSY_GPIO_PULLDOWN: ginit.Pull = GPIO_PULLDOWN; break; - default: ginit.Pull = GPIO_NOPULL; break; - } - ginit.Speed = GPIO_SPEED_LOW; - port = dsy_hal_map_get_port(&p->pin); - ginit.Pin = dsy_hal_map_get_pin(&p->pin); - start_clock_for_pin(p); - HAL_GPIO_Init(port, &ginit); - } - - void dsy_gpio_deinit(const dsy_gpio *p) - { - GPIO_TypeDef *port; - uint16_t pin; - port = dsy_hal_map_get_port(&p->pin); - pin = dsy_hal_map_get_pin(&p->pin); - HAL_GPIO_DeInit(port, pin); - } - - uint8_t dsy_gpio_read(const dsy_gpio *p) - { - return HAL_GPIO_ReadPin(dsy_hal_map_get_port(&p->pin), - dsy_hal_map_get_pin(&p->pin)); - // return HAL_GPIO_ReadPin((GPIO_TypeDef *)gpio_hal_port_map[p->pin.port], - // gpio_hal_pin_map[p->pin.pin]); - } - - void dsy_gpio_write(const dsy_gpio *p, uint8_t state) - { - return HAL_GPIO_WritePin(dsy_hal_map_get_port(&p->pin), - dsy_hal_map_get_pin(&p->pin), - (GPIO_PinState)(state > 0 ? 1 : 0)); - // HAL_GPIO_WritePin((GPIO_TypeDef *)gpio_hal_port_map[p->pin.port], - // gpio_hal_pin_map[p->pin.pin], - // (GPIO_PinState)(state > 0 ? 1 : 0)); - } - void dsy_gpio_toggle(const dsy_gpio *p) - { - return HAL_GPIO_TogglePin(dsy_hal_map_get_port(&p->pin), - dsy_hal_map_get_pin(&p->pin)); - // HAL_GPIO_TogglePin((GPIO_TypeDef *)gpio_hal_port_map[p->pin.port], - // gpio_hal_pin_map[p->pin.pin]); - } -} diff --git a/src/per/gpio.h b/src/per/gpio.h index 7b4182f7d..e37595daa 100644 --- a/src/per/gpio.h +++ b/src/per/gpio.h @@ -140,77 +140,5 @@ class GPIO } // namespace daisy - -/** @ingroup peripheral - * @addtogroup DEPRECATED-OLD-GPIO - * - * @brief Deprecated C API for GPIO is staying in place for a - * few versions to support backwards compatibility. - * - * This should not be used for anything new. - * @deprecated These should only be used for casting to configs, and are planned to be reomved in a future version. - * @{ - */ -extern "C" -{ - /** General Purpose IO driver */ - - /** Sets the mode of the GPIO */ - typedef enum - { - DSY_GPIO_MODE_INPUT, /**< & */ - DSY_GPIO_MODE_OUTPUT_PP, /**< Push-Pull */ - DSY_GPIO_MODE_OUTPUT_OD, /**< Open-Drain */ - DSY_GPIO_MODE_ANALOG, /**< & */ - DSY_GPIO_MODE_LAST, /**< & */ - } dsy_gpio_mode; - - /** Configures whether an internal Pull up or Pull down resistor is used */ - typedef enum - { - DSY_GPIO_NOPULL, /**< & */ - DSY_GPIO_PULLUP, /**< & */ - DSY_GPIO_PULLDOWN, /**< & */ - } dsy_gpio_pull; - - /** Struct for holding the pin, and configuration */ - typedef struct - { - dsy_gpio_pin pin; /**< & */ - dsy_gpio_mode mode; /**< & */ - dsy_gpio_pull pull; /**< & */ - } dsy_gpio; - - /** Initializes the gpio with the settings configured. - \param *p Pin pointer - */ - void dsy_gpio_init(const dsy_gpio *p); - - /** Deinitializes the gpio pin - \param *p Pin pointer - */ - void dsy_gpio_deinit(const dsy_gpio *p); - - /** - Reads the state of the gpio pin - \param *p Pin pointer - \return 1 if the pin is HIGH, and 0 if the pin is LOW */ - uint8_t dsy_gpio_read(const dsy_gpio *p); - - /** - Writes the state to the gpio pin - Pin will be set to 3v3 when state is 1, and 0V when state is 0 - \param *p Pin pointer - \param state State to write - */ - void dsy_gpio_write(const dsy_gpio *p, uint8_t state); - - /** Toggles the state of the pin so that it is not at the same state as it was previously. - \param *p Pin pointer - */ - void dsy_gpio_toggle(const dsy_gpio *p); - /**@} */ -} #endif - #endif diff --git a/src/per/i2c.cpp b/src/per/i2c.cpp index 533749471..1a7db87c9 100644 --- a/src/per/i2c.cpp +++ b/src/per/i2c.cpp @@ -1,7 +1,6 @@ #include "per/i2c.h" #include "sys/system.h" #include "util/scopedirqblocker.h" -#include "util/hal_map.h" namespace daisy { diff --git a/src/per/i2c.h b/src/per/i2c.h index 140a82fd0..f3903a7d0 100644 --- a/src/per/i2c.h +++ b/src/per/i2c.h @@ -1,4 +1,5 @@ #pragma once +#include "util/hal_map.h" #include "daisy_core.h" namespace daisy diff --git a/src/per/qspi.cpp b/src/per/qspi.cpp index ab268d9e6..970a6a4f4 100644 --- a/src/per/qspi.cpp +++ b/src/per/qspi.cpp @@ -4,8 +4,6 @@ #include "stm32h7xx_hal.h" #include "dev/flash_IS25LP080D.h" #include "dev/flash_IS25LP064A.h" -#include "util/hal_map.h" - // TODO: Add handling for alternate device types, // This will be a thing much sooner than anticipated diff --git a/src/per/qspi.h b/src/per/qspi.h index be8ad8b39..9dfa54ea3 100644 --- a/src/per/qspi.h +++ b/src/per/qspi.h @@ -4,7 +4,8 @@ #ifndef UNIT_TEST // for unit tests, a dummy implementation #include -#include "daisy_core.h" // Added for dsy_gpio_pin typedef +#include "daisy_core.h" +#include "util/hal_map.h" #define DSY_QSPI_TEXT \ __attribute__((section( \ diff --git a/src/per/rng.cpp b/src/per/rng.cpp index 2603d6d9f..27d1f3588 100644 --- a/src/per/rng.cpp +++ b/src/per/rng.cpp @@ -1,5 +1,5 @@ #include "rng.h" -#include "util/hal_map.h" +#include "stm32h7xx_hal.h" #include "sys/system.h" #define RNG_TIMEOUT 100 diff --git a/src/per/sai.cpp b/src/per/sai.cpp index 2014c8a15..b38a27436 100644 --- a/src/per/sai.cpp +++ b/src/per/sai.cpp @@ -1,9 +1,5 @@ #include "per/sai.h" #include "daisy_core.h" -extern "C" -{ -#include "util/hal_map.h" -} namespace daisy { diff --git a/src/per/sai.h b/src/per/sai.h index 71258180d..54c0e72a9 100644 --- a/src/per/sai.h +++ b/src/per/sai.h @@ -2,6 +2,7 @@ #ifndef DSY_SAI_H #define DSY_SAI_H +#include "util/hal_map.h" #include "daisy_core.h" namespace daisy diff --git a/src/per/sdmmc.cpp b/src/per/sdmmc.cpp index 600a10f97..c40af0c01 100644 --- a/src/per/sdmmc.cpp +++ b/src/per/sdmmc.cpp @@ -1,7 +1,4 @@ #include "per/sdmmc.h" -#include "util/hal_map.h" -//#include "fatfs.h" - using namespace daisy; diff --git a/src/per/sdmmc.h b/src/per/sdmmc.h index 625704263..05867f100 100644 --- a/src/per/sdmmc.h +++ b/src/per/sdmmc.h @@ -7,7 +7,7 @@ #define DSY_SDMMC_H /**< macro */ #include - +#include "stm32h7xx_hal.h" namespace daisy { diff --git a/src/per/spi.cpp b/src/per/spi.cpp index e913d4c98..2b56034c9 100644 --- a/src/per/spi.cpp +++ b/src/per/spi.cpp @@ -1,16 +1,10 @@ #include "per/spi.h" #include "util/scopedirqblocker.h" -extern "C" -{ -#include "util/hal_map.h" -} - // TODO // - fix up rest of lib so that we can add a spi_handle map to the hal map // - Add configuration for standard spi stuff. - using namespace daisy; static void Error_Handler() diff --git a/src/per/spi.h b/src/per/spi.h index 92af528a7..7ac0ffe91 100644 --- a/src/per/spi.h +++ b/src/per/spi.h @@ -3,6 +3,7 @@ #define DSY_SPI_H #include "daisy_core.h" +#include "util/hal_map.h" /* TODO: - Add documentation diff --git a/src/per/tim.cpp b/src/per/tim.cpp index fbd1a1a84..6c593452b 100644 --- a/src/per/tim.cpp +++ b/src/per/tim.cpp @@ -1,5 +1,4 @@ #include "per/tim.h" -#include "util/hal_map.h" #include "sys/system.h" diff --git a/src/per/tim.h b/src/per/tim.h index c37b25e0c..274b7cfc1 100644 --- a/src/per/tim.h +++ b/src/per/tim.h @@ -3,6 +3,7 @@ #define DSY_TIM_H #include +#include "stm32h7xx_hal.h" namespace daisy { diff --git a/src/per/uart.cpp b/src/per/uart.cpp index 426a5ad23..4d0658a16 100644 --- a/src/per/uart.cpp +++ b/src/per/uart.cpp @@ -5,11 +5,6 @@ #include "util/ringbuffer.h" #include "util/scopedirqblocker.h" -extern "C" -{ -#include "util/hal_map.h" -} - using namespace daisy; #define UART_RX_BUFF_SIZE 256 diff --git a/src/per/uart.h b/src/per/uart.h index 3f697fc0b..bcdf9691b 100644 --- a/src/per/uart.h +++ b/src/per/uart.h @@ -7,7 +7,7 @@ TODO #ifndef DSY_UART_H #define DSY_UART_H /**< macro */ #include "daisy_core.h" - +#include "util/hal_map.h" namespace daisy { diff --git a/src/util/hal_map.c b/src/util/hal_map.c deleted file mode 100644 index bd095a6f1..000000000 --- a/src/util/hal_map.c +++ /dev/null @@ -1,74 +0,0 @@ -#include "daisy_core.h" - -#include "stm32h7xx_hal.h" - -// Maps Daisy interface to STM32 HAL -- -// I'd like to get all of this stuff tucked away somewhere inbetween the HAL, and User level -// So that I can start to slowly replace HAL stuff over time. -// Also I don't like that this throws a warning for every library file that doesn't use it... - -const static GPIO_TypeDef* gpio_hal_port_map[DSY_GPIO_LAST] = { - GPIOA, - GPIOB, - GPIOC, - GPIOD, - GPIOE, - GPIOF, - GPIOG, - GPIOH, - GPIOI, - GPIOJ, - GPIOK, - NULL, -}; - -const static uint16_t gpio_hal_pin_map[16] = { - GPIO_PIN_0, - GPIO_PIN_1, - GPIO_PIN_2, - GPIO_PIN_3, - GPIO_PIN_4, - GPIO_PIN_5, - GPIO_PIN_6, - GPIO_PIN_7, - GPIO_PIN_8, - GPIO_PIN_9, - GPIO_PIN_10, - GPIO_PIN_11, - GPIO_PIN_12, - GPIO_PIN_13, - GPIO_PIN_14, - GPIO_PIN_15, -}; - -// GPIO FUNCTIONS - -GPIO_TypeDef* dsy_hal_map_get_port(const dsy_gpio_pin* p) -{ - return (GPIO_TypeDef*)gpio_hal_port_map[p->port]; -} -uint16_t dsy_hal_map_get_pin(const dsy_gpio_pin* p) -{ - return (uint16_t)gpio_hal_pin_map[p->pin]; -} - -void dsy_hal_map_gpio_clk_enable(dsy_gpio_port port) -{ - switch(port) - { - case DSY_GPIOA: __HAL_RCC_GPIOA_CLK_ENABLE(); return; - case DSY_GPIOB: __HAL_RCC_GPIOB_CLK_ENABLE(); return; - case DSY_GPIOC: __HAL_RCC_GPIOC_CLK_ENABLE(); return; - case DSY_GPIOD: __HAL_RCC_GPIOD_CLK_ENABLE(); return; - case DSY_GPIOE: __HAL_RCC_GPIOE_CLK_ENABLE(); return; - case DSY_GPIOF: __HAL_RCC_GPIOF_CLK_ENABLE(); return; - case DSY_GPIOG: __HAL_RCC_GPIOG_CLK_ENABLE(); return; - case DSY_GPIOH: __HAL_RCC_GPIOH_CLK_ENABLE(); return; - case DSY_GPIOI: __HAL_RCC_GPIOI_CLK_ENABLE(); return; - case DSY_GPIOJ: __HAL_RCC_GPIOJ_CLK_ENABLE(); return; - case DSY_GPIOK: __HAL_RCC_GPIOK_CLK_ENABLE(); return; - default: return; - } -} - -// ADC FUNCTIONS diff --git a/src/util/hal_map.h b/src/util/hal_map.h index 3e1f09f1b..6c30be397 100644 --- a/src/util/hal_map.h +++ b/src/util/hal_map.h @@ -52,34 +52,6 @@ inline void GPIOClockEnable(Pin p) } } // namespace daisy -extern "C" -{ -#endif - - /** global structs, and helper functions for interfacing with the stm32 HAL library - while it remains a dependancy. - This file should only be included from source files (c/cpp) - Including it from a header within libdaisy would expose the entire HAL to the users. - This should be an option for users, but should not be required. -*/ - - /** \param *p Pin pin to get - \return HAL GPIO_TypeDef as used in the HAL from a dsy_gpio_pin input. -*/ - GPIO_TypeDef *dsy_hal_map_get_port(const dsy_gpio_pin *p); - - /** \param *p Pin pin to get - \return HAL GPIO Pin as used in the HAL from a dsy_gpio_pin input. -*/ - uint16_t dsy_hal_map_get_pin(const dsy_gpio_pin *p); - - /** \param port port clock to enable -*/ - void dsy_hal_map_gpio_clk_enable(dsy_gpio_port port); - -#ifdef __cplusplus -} #endif - #endif /** @} */ From e5fae4d7a16326b242788af2f7f2b898f8806575 Mon Sep 17 00:00:00 2001 From: beserge Date: Tue, 27 Feb 2024 15:40:55 -0500 Subject: [PATCH 35/38] Remove hal_map.c from build systems --- CMakeLists.txt | 1 - Makefile | 1 - 2 files changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b56ffe6d4..239fddd2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,6 @@ add_library(${TARGET} STATIC ${MODULE_DIR}/per/sai.cpp ${MODULE_DIR}/per/sdmmc.cpp ${MODULE_DIR}/util/bsp_sd_diskio.c - ${MODULE_DIR}/util/hal_map.c ${MODULE_DIR}/util/oled_fonts.c ${MODULE_DIR}/util/sd_diskio.c ${MODULE_DIR}/util/usbh_diskio.c diff --git a/Makefile b/Makefile index c131a47d8..d4a7dea4c 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,6 @@ per/gpio \ per/sai \ per/sdmmc \ util/bsp_sd_diskio \ -util/hal_map \ util/oled_fonts \ util/sd_diskio \ util/unique_id \ From 708fd7193395dbbe0399fd38ddc13f21a5687d59 Mon Sep 17 00:00:00 2001 From: beserge Date: Tue, 27 Feb 2024 15:43:34 -0500 Subject: [PATCH 36/38] Reintroduce dsy_gpio_pin + implicit conversion to daisy::Pin Also: Added a deprecation warning to the dsy_gpio_pin struct Left out some of the additional stuff surrounding that struct, e.g. comparison operators, implicit cast from Pin to dsy_gpio_pin These would throw the deprecation warning, so theyve been left out I also added an implicit cast from dsy_gpio_pin to daisy::Pin This required moving the dsy_gpio_pin and port inside the daisy namespace --- src/daisy_core.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/daisy_core.h b/src/daisy_core.h index fcf0f2685..0908c7044 100644 --- a/src/daisy_core.h +++ b/src/daisy_core.h @@ -218,6 +218,52 @@ struct Pin constexpr bool operator!=(const Pin &rhs) const { return !operator==(rhs); } }; + +/** Enums and a simple struct for defining a hardware pin on the MCU + * These correlate with the stm32 datasheet, and are used to configure + * the hardware. + * + * This along with the dsy_gpio_pin class should no longer be used. + * They are available for backwards compatability. + * + * Please use GPIOPort enum and the Pin struct instead. + */ +typedef enum +{ + DSY_GPIOA, /**< & */ + DSY_GPIOB, /**< & */ + DSY_GPIOC, /**< & */ + DSY_GPIOD, /**< & */ + DSY_GPIOE, /**< & */ + DSY_GPIOF, /**< & */ + DSY_GPIOG, /**< & */ + DSY_GPIOH, /**< & */ + DSY_GPIOI, /**< & */ + DSY_GPIOJ, /**< & */ + DSY_GPIOK, /**< & */ + DSY_GPIOX, /** This is a non-existant port for unsupported bits of hardware. */ + DSY_GPIO_LAST, /** Final enum member */ +} dsy_gpio_port; + +/** Hardware define pins + * + * The dsy_gpio_pin struct should no longer be used, and is only available for + * backwards compatability. + * + * Please use Pin struct instead. + */ +[[deprecated("Use daisy::Pin instead")]] typedef struct +{ + dsy_gpio_port port; /**< & */ + uint8_t pin; /**< number 0-15 */ + + constexpr operator Pin() const + { + return Pin(static_cast(port), pin); + } + +} dsy_gpio_pin; + } // namespace daisy #endif // __cplusplus From eb3b268cdd1bd806fa9f94666a0c4a7cb7b417ea Mon Sep 17 00:00:00 2001 From: beserge Date: Tue, 27 Feb 2024 16:11:55 -0500 Subject: [PATCH 37/38] Fix unit tests Remove test making sure new pin could cast to old Add two conditionals so the hal_map wont be included during some tests --- src/per/spi.h | 3 +++ src/per/uart.h | 3 +++ tests/Pin_gtest.cpp | 13 ------------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/per/spi.h b/src/per/spi.h index 7ac0ffe91..5e6d2e6cc 100644 --- a/src/per/spi.h +++ b/src/per/spi.h @@ -3,7 +3,10 @@ #define DSY_SPI_H #include "daisy_core.h" + +#if !UNIT_TEST #include "util/hal_map.h" +#endif /* TODO: - Add documentation diff --git a/src/per/uart.h b/src/per/uart.h index bcdf9691b..52314f02a 100644 --- a/src/per/uart.h +++ b/src/per/uart.h @@ -7,7 +7,10 @@ TODO #ifndef DSY_UART_H #define DSY_UART_H /**< macro */ #include "daisy_core.h" + +#if !UNIT_TEST #include "util/hal_map.h" +#endif namespace daisy { diff --git a/tests/Pin_gtest.cpp b/tests/Pin_gtest.cpp index 7b10d4ee1..75d6972db 100644 --- a/tests/Pin_gtest.cpp +++ b/tests/Pin_gtest.cpp @@ -25,16 +25,3 @@ TEST(PinTests, c_copy) Pin dest = src; EXPECT_TRUE(src == dest); } - -TEST(PinTests, d_conversion) -{ - dsy_gpio_pin old_pin = {DSY_GPIOA, 5}; - - Pin new_pin = Pin(PORTA, 5); - - /** Using operator dsy_gpio_pin for implicit conversion */ - dsy_gpio_pin converted_pin = new_pin; - - EXPECT_EQ(old_pin.port, converted_pin.port); - EXPECT_EQ(old_pin.pin, converted_pin.pin); -} From 2830ceefd3f4d71ae1eb0f3fc602810143061c1b Mon Sep 17 00:00:00 2001 From: beserge Date: Wed, 28 Feb 2024 14:58:15 -0500 Subject: [PATCH 38/38] Initialize DaisySeed::seedgpio using constexpr pins from header --- src/daisy_seed.cpp | 66 +++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/daisy_seed.cpp b/src/daisy_seed.cpp index 09b27dc89..88e74ce4e 100644 --- a/src/daisy_seed.cpp +++ b/src/daisy_seed.cpp @@ -12,44 +12,44 @@ constexpr uint8_t SEED_TEST_POINT_PIN = 14; const Pin seedgpio[33] = { // GPIO 1-8 //{PORTA, 8}, // removed on Rev4 - Pin(PORTB, 12), - Pin(PORTC, 11), - Pin(PORTC, 10), - Pin(PORTC, 9), - Pin(PORTC, 8), - Pin(PORTD, 2), - Pin(PORTC, 12), + seed::D0, + seed::D1, + seed::D2, + seed::D3, + seed::D4, + seed::D5, + seed::D6, // GPIO 9-16 - Pin(PORTG, 10), - Pin(PORTG, 11), - Pin(PORTB, 4), - Pin(PORTB, 5), - Pin(PORTB, 8), - Pin(PORTB, 9), - Pin(PORTB, 6), - Pin(PORTB, 7), + seed::D7, + seed::D8, + seed::D9, + seed::D10, + seed::D11, + seed::D12, + seed::D13, + seed::D14, // GPIO 17-24 - Pin(PORTC, 0), - Pin(PORTA, 3), - Pin(PORTB, 1), - Pin(PORTA, 7), - Pin(PORTA, 6), - Pin(PORTC, 1), - Pin(PORTC, 4), - Pin(PORTA, 5), + seed::D15, + seed::D16, + seed::D17, + seed::D18, + seed::D19, + seed::D20, + seed::D21, + seed::D22, // GPIO 25-31 - Pin(PORTA, 4), - Pin(PORTA, 1), - Pin(PORTA, 0), - Pin(PORTD, 11), - Pin(PORTG, 9), - Pin(PORTA, 2), - Pin(PORTB, 14), - Pin(PORTB, 15), + seed::D23, + seed::D24, + seed::D25, + seed::D26, + seed::D27, + seed::D28, + seed::D29, + seed::D30, // Seed2DFM exclusive pins - Pin(PORTC, 2), - Pin(PORTC, 3), + seed::D31, + seed::D32, }; #else const GPIOPort seed_ports[32] = {