Skip to content

Commit

Permalink
Global GPIO/Pin Migration (#584)
Browse files Browse the repository at this point in the history
* Update DaisySeed to use GPIO

* Update DaisyPatch to use GPIO

* Update daisy::patch_sm to use GPIO

* Update DaisyField to use GPIO

* Update LED and RGBLed to use GPIO and Pin

* 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().

* Update HD44780 driver to use GPIO and Pin

* Update PCA9685 driver to use GPIO and Pin

* Update SSD130X driver to use GPIO and Pin

* Move SR595 Driver into daisy namespace

* Update SR595 driver to use GPIO and Pin

* Update 4021 driver with GPIO and Pin

* Update Encoder to use GPIO and Pin

* Update Switch driver to use GPIO and Pin

Also migrates from internal custom Pull representation to the global GPIO::Pull

* Update Switch3 to use GPIO and Pin

* Add Init() to GPIO for 0-parameter initialization

* Update ADC to use GPIO and Pin

* Update system to use GPIO and Pin

* Update multi-peripheral SPI driver with GPIO/Pin

* Update Midi to use Pin

* Update TLV493D to use Pin

* Update MCP23x17 and MAX11300 to use Pin

* Update DAC driver to use GPIO and Pin

* Update I2C driver to use GPIO and Pin

* Update UART to use GPIO and Pin

* Update SPI peripheral to use GPIO and Pin

* Update SAI peripheral to use GPIO and Pin

* Update QSPI peripheral to use GPIO and Pin

* Update outdated documentation

* Style compliance

* Fix ResetToBootloader (merge error)

* Replace old dsy_gpio in DaisySeed with modern GPIO

* Move patch_sm to modern GPIO

* Rip up all old GPIO usage

* Remove hal_map.c from build systems

* 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

* 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

* Initialize DaisySeed::seedgpio using constexpr pins from header

---------

Co-authored-by: beserge <[email protected]>
  • Loading branch information
stellar-aria and beserge authored Sep 20, 2024
1 parent 15e1dd5 commit f7dd38f
Show file tree
Hide file tree
Showing 65 changed files with 667 additions and 1,152 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions src/daisy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
122 changes: 44 additions & 78 deletions src/daisy_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -284,19 +216,53 @@ 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
/** 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 dsy_gpio_pin{.port = static_cast<dsy_gpio_port>(port),
.pin = pin};
return Pin(static_cast<GPIOPort>(port), pin);
}
};

} dsy_gpio_pin;

} // namespace daisy

Expand Down
5 changes: 1 addition & 4 deletions src/daisy_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/daisy_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class DaisyField

DaisySeed seed;
OledDisplay<SSD130x4WireSpi128x64Driver> display;
dsy_gpio gate_out;
GPIO gate_out;
GateIn gate_in;
LedDriverPca9685<2, true> led_driver;
Switch sw[SW_LAST];
Expand Down
9 changes: 2 additions & 7 deletions src/daisy_patch.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "daisy_patch.h"
#include "dev/codec_ak4556.h"

using namespace daisy;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -286,10 +284,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);
Expand Down
13 changes: 7 additions & 6 deletions src/daisy_patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,16 @@ 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 */
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<SSD130x4WireSpi128x64Driver> display; /**< & */

// TODO: Add class for Gate output
dsy_gpio gate_output; /**< & */
GPIO gate_output; /**< & */


private:
Expand Down
21 changes: 5 additions & 16 deletions src/daisy_patch_sm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,23 +330,12 @@ 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);
//gate_in_1.Init((dsy_gpio_pin *)&DaisyPatchSM::B10);
user_led.Init(PIN_USER_LED, GPIO::Mode::OUTPUT);
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();
Expand Down Expand Up @@ -453,7 +442,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;
Expand All @@ -473,7 +462,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()
{
Expand Down
6 changes: 3 additions & 3 deletions src/daisy_patch_sm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit f7dd38f

Please sign in to comment.