Skip to content

Commit f7dd38f

Browse files
Global GPIO/Pin Migration (#584)
* 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 <bensergentanis@gmail.com>
1 parent 15e1dd5 commit f7dd38f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+667
-1152
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ add_library(${TARGET} STATIC
1616
${MODULE_DIR}/per/sai.cpp
1717
${MODULE_DIR}/per/sdmmc.cpp
1818
${MODULE_DIR}/util/bsp_sd_diskio.c
19-
${MODULE_DIR}/util/hal_map.c
2019
${MODULE_DIR}/util/oled_fonts.c
2120
${MODULE_DIR}/util/sd_diskio.c
2221
${MODULE_DIR}/util/usbh_diskio.c

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ per/gpio \
99
per/sai \
1010
per/sdmmc \
1111
util/bsp_sd_diskio \
12-
util/hal_map \
1312
util/oled_fonts \
1413
util/sd_diskio \
1514
util/unique_id \

src/daisy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "hid/rgb_led.h"
4444
#include "dev/sr_595.h"
4545
#include "dev/apds9960.h"
46+
#include "dev/codec_ak4556.h"
4647
#include "dev/codec_pcm3060.h"
4748
#include "dev/codec_wm8731.h"
4849
#include "dev/dps310.h"

src/daisy_core.h

Lines changed: 44 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -167,74 +167,6 @@ FORCE_INLINE int32_t f2s32(float x)
167167
return (int32_t)(x * F2S32_SCALE);
168168
}
169169

170-
171-
/** Enums and a simple struct for defining a hardware pin on the MCU
172-
* These correlate with the stm32 datasheet, and are used to configure
173-
* the hardware.
174-
*
175-
* This along with the dsy_gpio_pin class should no longer be used.
176-
* They are available for backwards compatability.
177-
*
178-
* Please use GPIOPort enum and the Pin struct instead.
179-
*/
180-
typedef enum
181-
{
182-
DSY_GPIOA, /**< & */
183-
DSY_GPIOB, /**< & */
184-
DSY_GPIOC, /**< & */
185-
DSY_GPIOD, /**< & */
186-
DSY_GPIOE, /**< & */
187-
DSY_GPIOF, /**< & */
188-
DSY_GPIOG, /**< & */
189-
DSY_GPIOH, /**< & */
190-
DSY_GPIOI, /**< & */
191-
DSY_GPIOJ, /**< & */
192-
DSY_GPIOK, /**< & */
193-
DSY_GPIOX, /** This is a non-existant port for unsupported bits of hardware. */
194-
DSY_GPIO_LAST, /** Final enum member */
195-
} dsy_gpio_port;
196-
197-
/** Hardware define pins
198-
*
199-
* The dsy_gpio_pin struct should no longer be used, and is only available for
200-
* backwards compatability.
201-
*
202-
* Please use Pin struct instead.
203-
*/
204-
typedef struct
205-
{
206-
dsy_gpio_port port; /**< & */
207-
uint8_t pin; /**< number 0-15 */
208-
} dsy_gpio_pin;
209-
210-
/** Helper for creating pins from port/pin combos easily
211-
*
212-
* The dsy_gpio_pin struct should no longer be used, and is only available for
213-
* backwards compatability.
214-
*
215-
* Please use Pin struct instead.
216-
*/
217-
FORCE_INLINE dsy_gpio_pin dsy_pin(dsy_gpio_port port, uint8_t pin)
218-
{
219-
dsy_gpio_pin p;
220-
p.port = port;
221-
p.pin = pin;
222-
return p;
223-
}
224-
225-
/** Helper for testing sameness of two dsy_gpio_pins
226-
* \return 1 if same, 0 if different
227-
*
228-
* The dsy_gpio_pin struct should no longer be used, and is only available for
229-
* backwards compatability.
230-
*
231-
* Please use Pin struct instead.
232-
*/
233-
FORCE_INLINE uint8_t dsy_pin_cmp(dsy_gpio_pin *a, dsy_gpio_pin *b)
234-
{
235-
return ((a->port == b->port) && (a->pin == b->pin));
236-
}
237-
238170
#ifdef __cplusplus
239171

240172
namespace daisy
@@ -284,19 +216,53 @@ struct Pin
284216

285217
/** @brief comparison operator for checking inequality between Pin objects */
286218
constexpr bool operator!=(const Pin &rhs) const { return !operator==(rhs); }
219+
};
220+
287221

288-
/** @brief conversion operation for converting to the old-style representation
289-
* of a pin.
290-
*
291-
* This allows the new Pin type to be used in place of the older, dsy_gpio_pin
292-
* type.
293-
*/
294-
constexpr operator dsy_gpio_pin() const
222+
/** Enums and a simple struct for defining a hardware pin on the MCU
223+
* These correlate with the stm32 datasheet, and are used to configure
224+
* the hardware.
225+
*
226+
* This along with the dsy_gpio_pin class should no longer be used.
227+
* They are available for backwards compatability.
228+
*
229+
* Please use GPIOPort enum and the Pin struct instead.
230+
*/
231+
typedef enum
232+
{
233+
DSY_GPIOA, /**< & */
234+
DSY_GPIOB, /**< & */
235+
DSY_GPIOC, /**< & */
236+
DSY_GPIOD, /**< & */
237+
DSY_GPIOE, /**< & */
238+
DSY_GPIOF, /**< & */
239+
DSY_GPIOG, /**< & */
240+
DSY_GPIOH, /**< & */
241+
DSY_GPIOI, /**< & */
242+
DSY_GPIOJ, /**< & */
243+
DSY_GPIOK, /**< & */
244+
DSY_GPIOX, /** This is a non-existant port for unsupported bits of hardware. */
245+
DSY_GPIO_LAST, /** Final enum member */
246+
} dsy_gpio_port;
247+
248+
/** Hardware define pins
249+
*
250+
* The dsy_gpio_pin struct should no longer be used, and is only available for
251+
* backwards compatability.
252+
*
253+
* Please use Pin struct instead.
254+
*/
255+
[[deprecated("Use daisy::Pin instead")]] typedef struct
256+
{
257+
dsy_gpio_port port; /**< & */
258+
uint8_t pin; /**< number 0-15 */
259+
260+
constexpr operator Pin() const
295261
{
296-
return dsy_gpio_pin{.port = static_cast<dsy_gpio_port>(port),
297-
.pin = pin};
262+
return Pin(static_cast<GPIOPort>(port), pin);
298263
}
299-
};
264+
265+
} dsy_gpio_pin;
300266

301267
} // namespace daisy
302268

src/daisy_field.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,7 @@ void DaisyField::Init(bool boost)
142142
// Gate In
143143
gate_in.Init(PIN_GATE_IN);
144144
// Gate Out
145-
gate_out.mode = DSY_GPIO_MODE_OUTPUT_PP;
146-
gate_out.pull = DSY_GPIO_NOPULL;
147-
gate_out.pin = PIN_GATE_OUT;
148-
dsy_gpio_init(&gate_out);
145+
gate_out.Init(PIN_GATE_OUT, GPIO::Mode::OUTPUT);
149146

150147
//midi
151148
MidiUartHandler::Config midi_config;

src/daisy_field.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class DaisyField
212212

213213
DaisySeed seed;
214214
OledDisplay<SSD130x4WireSpi128x64Driver> display;
215-
dsy_gpio gate_out;
215+
GPIO gate_out;
216216
GateIn gate_in;
217217
LedDriverPca9685<2, true> led_driver;
218218
Switch sw[SW_LAST];

src/daisy_patch.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "daisy_patch.h"
2-
#include "dev/codec_ak4556.h"
32

43
using namespace daisy;
54

@@ -216,8 +215,7 @@ void DaisyPatch::InitAudio()
216215

217216
// Reset Pin for AK4556
218217
// Built-in AK4556 was reset during Seed Init
219-
dsy_gpio_pin codec_reset_pin = PIN_AK4556_RESET;
220-
Ak4556::Init(codec_reset_pin);
218+
codec.Init(PIN_AK4556_RESET);
221219

222220
// Reinit Audio for _both_ codecs...
223221
AudioHandle::Config cfg;
@@ -286,10 +284,7 @@ void DaisyPatch::InitEncoder()
286284
void DaisyPatch::InitGates()
287285
{
288286
// Gate Output
289-
gate_output.pin = PIN_GATE_OUT;
290-
gate_output.mode = DSY_GPIO_MODE_OUTPUT_PP;
291-
gate_output.pull = DSY_GPIO_NOPULL;
292-
dsy_gpio_init(&gate_output);
287+
gate_output.Init(PIN_GATE_OUT, GPIO::Mode::OUTPUT);
293288

294289
// Gate Inputs
295290
gate_input[GATE_IN_1].Init(PIN_GATE_IN_1);

src/daisy_patch.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,16 @@ class DaisyPatch
114114
/* These are exposed for the user to access and manipulate directly
115115
Helper functions above provide easier access to much of what they are capable of.
116116
*/
117-
DaisySeed seed; /**< Seed object */
118-
Encoder encoder; /**< Encoder object */
119-
AnalogControl controls[CTRL_LAST]; /**< Array of controls*/
120-
GateIn gate_input[GATE_IN_LAST]; /**< Gate inputs */
121-
MidiUartHandler midi; /**< Handles midi*/
117+
DaisySeed seed; /**< Seed object */
118+
Ak4556 codec; /**< Patch's second CODEC */
119+
Encoder encoder; /**< Encoder object */
120+
AnalogControl controls[CTRL_LAST]; /**< Array of controls*/
121+
GateIn gate_input[GATE_IN_LAST]; /**< Gate inputs */
122+
MidiUartHandler midi; /**< Handles midi*/
122123
OledDisplay<SSD130x4WireSpi128x64Driver> display; /**< & */
123124

124125
// TODO: Add class for Gate output
125-
dsy_gpio gate_output; /**< & */
126+
GPIO gate_output; /**< & */
126127

127128

128129
private:

src/daisy_patch_sm.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -330,23 +330,12 @@ namespace patch_sm
330330
}
331331

332332
/** Fixed-function Digital I/O */
333-
user_led.mode = DSY_GPIO_MODE_OUTPUT_PP;
334-
user_led.pull = DSY_GPIO_NOPULL;
335-
user_led.pin = PIN_USER_LED;
336-
dsy_gpio_init(&user_led);
337-
//gate_in_1.Init((dsy_gpio_pin *)&DaisyPatchSM::B10);
333+
user_led.Init(PIN_USER_LED, GPIO::Mode::OUTPUT);
338334
gate_in_1.Init(B10);
339335
gate_in_2.Init(B9);
340336

341-
gate_out_1.mode = DSY_GPIO_MODE_OUTPUT_PP;
342-
gate_out_1.pull = DSY_GPIO_NOPULL;
343-
gate_out_1.pin = B5;
344-
dsy_gpio_init(&gate_out_1);
345-
346-
gate_out_2.mode = DSY_GPIO_MODE_OUTPUT_PP;
347-
gate_out_2.pull = DSY_GPIO_NOPULL;
348-
gate_out_2.pin = B6;
349-
dsy_gpio_init(&gate_out_2);
337+
gate_out_1.Init(B5, GPIO::Mode::OUTPUT);
338+
gate_out_2.Init(B6, GPIO::Mode::OUTPUT);
350339

351340
/** DAC init */
352341
pimpl_->InitDac();
@@ -453,7 +442,7 @@ namespace patch_sm
453442

454443
float DaisyPatchSM::GetAdcValue(int idx) { return controls[idx].Value(); }
455444

456-
dsy_gpio_pin DaisyPatchSM::GetPin(const PinBank bank, const int idx)
445+
Pin DaisyPatchSM::GetPin(const PinBank bank, const int idx)
457446
{
458447
if(idx <= 0 || idx > 10)
459448
return DUMMYPIN;
@@ -473,7 +462,7 @@ namespace patch_sm
473462
pimpl_->WriteCvOut(channel, voltage);
474463
}
475464

476-
void DaisyPatchSM::SetLed(bool state) { dsy_gpio_write(&user_led, state); }
465+
void DaisyPatchSM::SetLed(bool state) { user_led.Write(state); }
477466

478467
bool DaisyPatchSM::ValidateSDRAM()
479468
{

src/daisy_patch_sm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ namespace patch_sm
143143
* \param idx pin number between 1 and 10 for each of the pins on each header.
144144
* \deprecated please use the Pin definitions in daisy::patch_sm instead
145145
*/
146-
dsy_gpio_pin GetPin(const PinBank bank, const int idx);
146+
Pin GetPin(const PinBank bank, const int idx);
147147

148148
/** Starts the DAC for the CV Outputs
149149
*
@@ -251,10 +251,10 @@ namespace patch_sm
251251
DacHandle dac;
252252

253253
/** Dedicated Function Pins */
254-
dsy_gpio user_led;
254+
GPIO user_led;
255255
AnalogControl controls[ADC_LAST];
256256
GateIn gate_in_1, gate_in_2;
257-
dsy_gpio gate_out_1, gate_out_2;
257+
GPIO gate_out_1, gate_out_2;
258258

259259

260260
/** Pin Accessors for the DaisyPatchSM hardware

0 commit comments

Comments
 (0)