Skip to content

Commit 4a629b9

Browse files
authored
start adjusting daisy for new pin assignments (#310)
* start adjusting daisy for new pin assignments * adjust GPIO defs * correct codec config and init * remove pullup from patch.init switch * update changelog
1 parent 415a859 commit 4a629b9

11 files changed

Lines changed: 280 additions & 326 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Updates:
2323

2424
* drop py3.8 - add py3.13
2525
* integrate json2daisy library, tests and documentation
26+
* move to libDaisy 8.x pin definitions
2627

2728
0.13.4
2829
-----

hvcc/generators/c2daisy/json2daisy/json2daisy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ def generate_header(board_description_dict: dict) -> 'tuple[str, dict]':
304304
).from_string(header_str)
305305

306306
rendered_header = header_env.render(replacements)
307+
rendered_header_lines = rendered_header.splitlines()
308+
rendered_header = "\n".join(line.rstrip() for line in rendered_header_lines) + "\n"
307309

308310
# removing all unnecessary fields
309311
for comp in components:

hvcc/generators/c2daisy/json2daisy/resources/component_defs.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
]
1313
},
1414
"Switch": {
15-
"map_init": "{name}.Init(som.GetPin({pin}), som.AudioCallbackRate(), {type}, {polarity}, {pull});",
15+
"map_init": "{name}.Init(som.GetPin({pin}), som.AudioCallbackRate(), {type}, {polarity});",
1616
"typename": "daisy::Switch",
1717
"direction": "in",
1818
"pin": "a",
1919
"type": "daisy::Switch::TYPE_MOMENTARY",
2020
"polarity": "daisy::Switch::POLARITY_INVERTED",
21-
"pull": "daisy::Switch::PULL_UP",
2221
"process": "{name}.Debounce();",
2322
"updaterate": "{name}.SetUpdateRate(som.AudioCallbackRate());",
2423
"mapping": [
@@ -127,7 +126,7 @@
127126
]
128127
},
129128
"GateIn": {
130-
"map_init": "dsy_gpio_pin {name}_pin = som.GetPin({pin});\n {name}.Init(&{name}_pin, {invert});",
129+
"map_init": "{name}.Init(som.GetPin({pin}), {invert});",
131130
"typename": "daisy::GateIn",
132131
"direction": "in",
133132
"pin": "a",
@@ -221,16 +220,16 @@
221220
]
222221
},
223222
"GateOut": {
224-
"map_init": "{name}.pin = som.GetPin({pin});\n {name}.mode = {mode};\n {name}.pull = {pull};\n dsy_gpio_init(&{name});",
225-
"typename": "dsy_gpio",
223+
"map_init": "{name}.Init(som.GetPin({pin}), {mode}, {pull});",
224+
"typename": "daisy::GPIO",
226225
"direction": "out",
227226
"pin": "a",
228-
"mode": "DSY_GPIO_MODE_OUTPUT_PP",
229-
"pull": "DSY_GPIO_NOPULL",
227+
"mode": "daisy::GPIO::Mode::OUTPUT",
228+
"pull": "daisy::GPIO::Pull::NOPULL",
230229
"mapping": [
231230
{
232231
"name": "{name}",
233-
"set": "dsy_gpio_write(&{class_name}.{name}, {value});",
232+
"set": "{class_name}.{name}.Write({value});",
234233
"where": "hook"
235234
}
236235
]

hvcc/generators/c2daisy/json2daisy/resources/component_defs_patchsm.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
]
1313
},
1414
"Switch": {
15-
"map_init": "{name}.Init(daisy::patch_sm::DaisyPatchSM::{pin}, som.AudioCallbackRate(), {type}, {polarity}, {pull});",
15+
"map_init": "{name}.Init(daisy::patch_sm::DaisyPatchSM::{pin}, som.AudioCallbackRate(), {type}, {polarity});",
1616
"typename": "daisy::Switch",
1717
"direction": "in",
1818
"pin": "a",
1919
"type": "daisy::Switch::TYPE_MOMENTARY",
2020
"polarity": "daisy::Switch::POLARITY_INVERTED",
21-
"pull": "daisy::Switch::PULL_UP",
2221
"process": "{name}.Debounce();",
2322
"updaterate": "{name}.SetUpdateRate(som.AudioCallbackRate());",
2423
"mapping": [
@@ -221,17 +220,17 @@
221220
]
222221
},
223222
"GateOut": {
224-
"map_init": "{name}.pin = daisy::patch_sm::DaisyPatchSM::{pin};\n\t\t{name}.mode = {mode};\n\t\t{name}.pull = {pull};\n\t\tdsy_gpio_init(&{name});",
225-
"typename": "dsy_gpio",
223+
"map_init": "{name}.Init(daisy::patch_sm::DaisyPatchSM::{pin}, {mode}, {pull});",
224+
"typename": "daisy::GPIO",
226225
"direction": "out",
227226
"pin": "a",
228227
"default_prefix": "som.",
229-
"mode": "DSY_GPIO_MODE_OUTPUT_PP",
230-
"pull": "DSY_GPIO_NOPULL",
228+
"mode": "daisy::GPIO::Mode::OUTPUT",
229+
"pull": "daisy::GPIO::Pull::NOPULL",
231230
"mapping": [
232231
{
233232
"name": "{name}",
234-
"set": "dsy_gpio_write(&{class_name}.{default_prefix}{name}, {value});"
233+
"set": "{class_name}.{default_prefix}{name}.Write({value});"
235234
}
236235
]
237236
},

hvcc/generators/c2daisy/json2daisy/templates/daisy.h

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -24,97 +24,97 @@ struct Daisy{{ name|capitalize }} {
2424
/** Initializes the board according to the JSON board description
2525
* \param boost boosts the clock speed from 400 to 480 MHz
2626
*/
27-
void Init(bool boost=true)
27+
void Init(bool boost=true)
2828
{
2929
{% if som == 'seed' %}
3030
som.Configure();
3131
som.Init(boost);
3232
{% else %}
3333
som.Init();
3434
{% endif %}
35-
{% if init != '' %}
35+
{% if init != '' %}
3636

37-
{{init}}
37+
{{init}}
3838
{% endif %}
3939
{% if i2c != '' %}
4040

4141
// i2c
42-
{{ i2c }}
42+
{{ i2c }}
4343
{% endif %}
44-
{% if PCA9685 != '' %}
44+
{% if PCA9685 != '' %}
4545

4646
// LED Drivers
47-
{{ PCA9685 }}
47+
{{ PCA9685 }}
4848
{% endif %}
49-
{% if Switch != '' %}
49+
{% if Switch != '' %}
5050

5151
// Switches
52-
{{ Switch }}
52+
{{ Switch }}
5353
{% endif %}
5454
{% if Switch3 != '' %}
5555

5656
// SPDT Switches
57-
{{ Switch3 }}
57+
{{ Switch3 }}
5858
{% endif %}
59-
{% if CD4021 != '' %}
59+
{% if CD4021 != '' %}
6060

6161
// Muxes
62-
{{ CD4021 }}
62+
{{ CD4021 }}
6363
{% endif %}
64-
{% if GateIn != '' %}
64+
{% if GateIn != '' %}
6565

6666
// Gate ins
67-
{{ GateIn }}
67+
{{ GateIn }}
6868
{% endif %}
69-
{% if Encoder != '' %}
69+
{% if Encoder != '' %}
7070

7171
// Rotary encoders
72-
{{ Encoder }}
72+
{{ Encoder }}
7373
{% endif %}
74-
{% if init_single != '' %}
74+
{% if init_single != '' %}
7575

7676
// Single channel ADC initialization
77-
{{ init_single }}
77+
{{ init_single }}
7878
{% endif %}
7979
{% if som == 'seed' %}
8080
{% if analogcount > 0 %}
8181
som.adc.Init(cfg, ANALOG_COUNT);
8282
{% endif %}
8383
{% endif %}
84-
{% if ctrl_init != '' %}
84+
{% if ctrl_init != '' %}
8585

8686
// AnalogControl objects
87-
{{ ctrl_init }}
87+
{{ ctrl_init }}
8888
{% endif %}
89-
{% if CD4051AnalogControl != '' %}
89+
{% if CD4051AnalogControl != '' %}
9090

9191
// Multiplexed AnlogControl objects
92-
{{ CD4051AnalogControl }}
92+
{{ CD4051AnalogControl }}
9393
{% endif %}
94-
{% if Led != '' %}
94+
{% if Led != '' %}
9595

9696
// LEDs
97-
{{ Led }}
97+
{{ Led }}
9898
{% endif %}
9999
{% if RgbLed != '' %}
100100

101-
// RBG LEDs
102-
{{ RgbLed }}
101+
// RBG LEDs
102+
{{ RgbLed }}
103103
{% endif %}
104-
{% if GateOut != '' %}
104+
{% if GateOut != '' %}
105105

106106
// Gate outs
107-
{{ GateOut }}
107+
{{ GateOut }}
108108
{% endif %}
109109
{% if CVOuts != '' %}
110110

111-
// DAC
112-
{{ CVOuts }}
111+
// DAC
112+
{{ CVOuts }}
113113
{% endif %}
114114
{% if display != '' %}
115115

116116
// Display
117-
{{ display }}
117+
{{ display }}
118118
{% endif %}
119119
{% if MotorShield != '' %}
120120

@@ -204,11 +204,11 @@ struct Daisy{{ name|capitalize }} {
204204
sai_config[0].b_sync = daisy::SaiHandle::Config::Sync::SLAVE;
205205
sai_config[0].a_dir = daisy::SaiHandle::Config::Direction::TRANSMIT;
206206
sai_config[0].b_dir = daisy::SaiHandle::Config::Direction::RECEIVE;
207-
sai_config[0].pin_config.fs = {DSY_GPIOE, 4};
208-
sai_config[0].pin_config.mclk = {DSY_GPIOE, 2};
209-
sai_config[0].pin_config.sck = {DSY_GPIOE, 5};
210-
sai_config[0].pin_config.sa = {DSY_GPIOE, 6};
211-
sai_config[0].pin_config.sb = {DSY_GPIOE, 3};
207+
sai_config[0].pin_config.fs = daisy::Pin(daisy::PORTE, 4);
208+
sai_config[0].pin_config.mclk = daisy::Pin(daisy::PORTE, 2);
209+
sai_config[0].pin_config.sck = daisy::Pin(daisy::PORTE, 5);
210+
sai_config[0].pin_config.sa = daisy::Pin(daisy::PORTE, 6);
211+
sai_config[0].pin_config.sb = daisy::Pin(daisy::PORTE, 3);
212212

213213
{% for codec in external_codecs %}
214214
sai_config[{{loop.index}}].periph = daisy::SaiHandle::Config::Peripheral::{{codec.periph}};
@@ -231,15 +231,16 @@ struct Daisy{{ name|capitalize }} {
231231
sai_handle[{{loop.index}}].Init(sai_config[{{loop.index}}]);
232232
{% endfor %}
233233

234-
dsy_gpio_pin codec_reset_pin = som.GetPin(29);
235-
daisy::Ak4556::Init(codec_reset_pin);
234+
daisy::Pin codec_reset_pin = som.GetPin(29);
235+
daisy::Ak4556 codec;
236+
codec.Init(codec_reset_pin);
236237

237238
daisy::AudioHandle::Config cfg;
238239
cfg.blocksize = 48;
239240
cfg.samplerate = daisy::SaiHandle::Config::SampleRate::SAI_48KHZ;
240241
cfg.postgain = 0.5f;
241242
som.audio_handle.Init(
242-
cfg,
243+
cfg,
243244
sai_handle[0]
244245
{% for codec in external_codecs %}
245246
,sai_handle[{{loop.index}}]
@@ -255,20 +256,20 @@ struct Daisy{{ name|capitalize }} {
255256
}
256257

257258
/** Handles all the controls processing that needs to occur at the block rate
258-
*
259+
*
259260
*/
260-
void ProcessAllControls()
261+
void ProcessAllControls()
261262
{
262-
{% if process != '' %}
263-
{{ process }}
263+
{% if process != '' %}
264+
{{ process }}
264265
{% endif %}
265266
{% if som != 'seed' %}
266267
som.ProcessAllControls();
267268
{% endif %}
268269
}
269270

270271
/** Handles all the maintenance processing. This should be run last within the audio callback.
271-
*
272+
*
272273
*/
273274
void PostProcess()
274275
{
@@ -279,7 +280,7 @@ struct Daisy{{ name|capitalize }} {
279280
}
280281

281282
/** Handles processing that shouldn't occur in the audio block, such as blocking transfers
282-
*
283+
*
283284
*/
284285
void LoopProcess()
285286
{
@@ -289,7 +290,7 @@ struct Daisy{{ name|capitalize }} {
289290
/** Sets the audio sample rate
290291
* \param sample_rate the new sample rate in Hz
291292
*/
292-
void SetAudioSampleRate(size_t sample_rate)
293+
void SetAudioSampleRate(size_t sample_rate)
293294
{
294295
{% if som == 'seed' or som == 'petal_125b_sm' %}
295296
daisy::SaiHandle::Config::SampleRate enum_rate;
@@ -313,13 +314,13 @@ struct Daisy{{ name|capitalize }} {
313314
/** Sets the audio block size
314315
* \param block_size the new block size in words
315316
*/
316-
inline void SetAudioBlockSize(size_t block_size)
317+
inline void SetAudioBlockSize(size_t block_size)
317318
{
318319
som.SetAudioBlockSize(block_size);
319320
}
320321

321322
/** Starts up the audio callback process with the given callback
322-
*
323+
*
323324
*/
324325
inline void StartAudio(daisy::AudioHandle::AudioCallback cb)
325326
{

0 commit comments

Comments
 (0)