Skip to content

Commit

Permalink
Update daisy::patch_sm
Browse files Browse the repository at this point in the history
This updates the patch_sm class to use the new Pin objects, which
necessitated restructuring the pin definitions in the header file in a
way that now exposes them similarly to the daisy::seed namespace, and
removes the need for the now-deprecated GetPin method.
  • Loading branch information
stellar-aria committed May 29, 2023
1 parent e81050c commit 5c30e60
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 145 deletions.
205 changes: 71 additions & 134 deletions src/daisy_patch_sm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,116 +6,29 @@ namespace daisy
namespace patch_sm
{
/** Const definitions */
static constexpr dsy_gpio_pin DUMMYPIN = {DSY_GPIOX, 0};
static constexpr dsy_gpio_pin PIN_ADC_CTRL_1 = {DSY_GPIOA, 3};
static constexpr dsy_gpio_pin PIN_ADC_CTRL_2 = {DSY_GPIOA, 6};
static constexpr dsy_gpio_pin PIN_ADC_CTRL_3 = {DSY_GPIOA, 2};
static constexpr dsy_gpio_pin PIN_ADC_CTRL_4 = {DSY_GPIOA, 7};
static constexpr dsy_gpio_pin PIN_ADC_CTRL_5 = {DSY_GPIOB, 1};
static constexpr dsy_gpio_pin PIN_ADC_CTRL_6 = {DSY_GPIOC, 4};
static constexpr dsy_gpio_pin PIN_ADC_CTRL_7 = {DSY_GPIOC, 0};
static constexpr dsy_gpio_pin PIN_ADC_CTRL_8 = {DSY_GPIOC, 1};
static constexpr dsy_gpio_pin PIN_ADC_CTRL_9 = {DSY_GPIOA, 1};
static constexpr dsy_gpio_pin PIN_ADC_CTRL_10 = {DSY_GPIOA, 0};
static constexpr dsy_gpio_pin PIN_ADC_CTRL_11 = {DSY_GPIOC, 3};
static constexpr dsy_gpio_pin PIN_ADC_CTRL_12 = {DSY_GPIOC, 2};
static constexpr dsy_gpio_pin PIN_USER_LED = {DSY_GPIOC, 7};

const dsy_gpio_pin kPinMap[4][10] = {
/** Header Bank A */
{
DUMMYPIN, /**< A1 - -12V Power Input */
{DSY_GPIOA, 1}, /**< A2 - UART1 Rx */
{DSY_GPIOA, 0}, /**< A3 - UART1 Tx */
DUMMYPIN, /**< A4 - GND */
DUMMYPIN, /**< A5 - +12V Power Input */
DUMMYPIN, /**< A6 - +5V Power Output */
DUMMYPIN, /**< A7 - GND */
{DSY_GPIOB, 14}, /**< A8 - USB DM */
{DSY_GPIOB, 15}, /**< A9 - USB DP */
DUMMYPIN, /**< A10 - +3V3 Power Output */
},
/** Header Bank B */
{
DUMMYPIN, /**< B1 - Audio Out Right */
DUMMYPIN, /**< B2 - Audio Out Left*/
DUMMYPIN, /**< B3 - Audio In Right */
DUMMYPIN, /**< B4 - Audio In Left */
{DSY_GPIOC, 14}, /**< B5 - GATE OUT 1 */
{DSY_GPIOC, 13}, /**< B6 - GATE OUT 2 */
{DSY_GPIOB, 8}, /**< B7 - I2C1 SCL */
{DSY_GPIOB, 9}, /**< B8 - I2C1 SDA */
{DSY_GPIOG, 14}, /**< B9 - GATE IN 2 */
{DSY_GPIOG, 13}, /**< B10 - GATE IN 1 */
},
/** Header Bank C */
{
{DSY_GPIOA, 5}, /**< C1 - CV Out 2 */
PIN_ADC_CTRL_4, /**< C2 - CV In 4 */
PIN_ADC_CTRL_3, /**< C3 - CV In 3 */
PIN_ADC_CTRL_2, /**< C4 - CV In 2 */
PIN_ADC_CTRL_1, /**< C5 - CV In 1 */
PIN_ADC_CTRL_5, /**< C6 - CV In 5 */
PIN_ADC_CTRL_6, /**< C7 - CV In 6 */
PIN_ADC_CTRL_7, /**< C8 - CV In 7 */
PIN_ADC_CTRL_8, /**< C9 - CV In 8 */
{DSY_GPIOA, 4}, /**< C10 - CV Out 1 */
},
/** Header Bank D */
{
{DSY_GPIOB, 4}, /**< D1 - SPI2 CS */
{DSY_GPIOC, 11}, /**< D2 - SDMMC D3 */
{DSY_GPIOC, 10}, /**< D3 - SDMMC D2*/
{DSY_GPIOC, 9}, /**< D4 - SDMMC D1*/
{DSY_GPIOC, 8}, /**< D5 - SDMMC D0 */
{DSY_GPIOC, 12}, /**< D6 - SDMMC CK */
{DSY_GPIOD, 2}, /**< D7 - SDMMC CMD */
{DSY_GPIOC, 2}, /**< D8 - SPI2 MISO */
{DSY_GPIOC, 3}, /**< D9 - SPI2 MOSI */
{DSY_GPIOD, 3}, /**< D10 - SPI2 SCK */
},
};

const dsy_gpio_pin DaisyPatchSM::A1 = kPinMap[0][0];
const dsy_gpio_pin DaisyPatchSM::A2 = kPinMap[0][1];
const dsy_gpio_pin DaisyPatchSM::A3 = kPinMap[0][2];
const dsy_gpio_pin DaisyPatchSM::A4 = kPinMap[0][3];
const dsy_gpio_pin DaisyPatchSM::A5 = kPinMap[0][4];
const dsy_gpio_pin DaisyPatchSM::A6 = kPinMap[0][5];
const dsy_gpio_pin DaisyPatchSM::A7 = kPinMap[0][6];
const dsy_gpio_pin DaisyPatchSM::A8 = kPinMap[0][7];
const dsy_gpio_pin DaisyPatchSM::A9 = kPinMap[0][8];
const dsy_gpio_pin DaisyPatchSM::A10 = kPinMap[0][9];
const dsy_gpio_pin DaisyPatchSM::B1 = kPinMap[1][0];
const dsy_gpio_pin DaisyPatchSM::B2 = kPinMap[1][1];
const dsy_gpio_pin DaisyPatchSM::B3 = kPinMap[1][2];
const dsy_gpio_pin DaisyPatchSM::B4 = kPinMap[1][3];
const dsy_gpio_pin DaisyPatchSM::B5 = kPinMap[1][4];
const dsy_gpio_pin DaisyPatchSM::B6 = kPinMap[1][5];
const dsy_gpio_pin DaisyPatchSM::B7 = kPinMap[1][6];
const dsy_gpio_pin DaisyPatchSM::B8 = kPinMap[1][7];
const dsy_gpio_pin DaisyPatchSM::B9 = kPinMap[1][8];
const dsy_gpio_pin DaisyPatchSM::B10 = kPinMap[1][9];
const dsy_gpio_pin DaisyPatchSM::C1 = kPinMap[2][0];
const dsy_gpio_pin DaisyPatchSM::C2 = kPinMap[2][1];
const dsy_gpio_pin DaisyPatchSM::C3 = kPinMap[2][2];
const dsy_gpio_pin DaisyPatchSM::C4 = kPinMap[2][3];
const dsy_gpio_pin DaisyPatchSM::C5 = kPinMap[2][4];
const dsy_gpio_pin DaisyPatchSM::C6 = kPinMap[2][5];
const dsy_gpio_pin DaisyPatchSM::C7 = kPinMap[2][6];
const dsy_gpio_pin DaisyPatchSM::C8 = kPinMap[2][7];
const dsy_gpio_pin DaisyPatchSM::C9 = kPinMap[2][8];
const dsy_gpio_pin DaisyPatchSM::C10 = kPinMap[2][9];
const dsy_gpio_pin DaisyPatchSM::D1 = kPinMap[3][0];
const dsy_gpio_pin DaisyPatchSM::D2 = kPinMap[3][1];
const dsy_gpio_pin DaisyPatchSM::D3 = kPinMap[3][2];
const dsy_gpio_pin DaisyPatchSM::D4 = kPinMap[3][3];
const dsy_gpio_pin DaisyPatchSM::D5 = kPinMap[3][4];
const dsy_gpio_pin DaisyPatchSM::D6 = kPinMap[3][5];
const dsy_gpio_pin DaisyPatchSM::D7 = kPinMap[3][6];
const dsy_gpio_pin DaisyPatchSM::D8 = kPinMap[3][7];
const dsy_gpio_pin DaisyPatchSM::D9 = kPinMap[3][8];
const dsy_gpio_pin DaisyPatchSM::D10 = kPinMap[3][9];
constexpr Pin DUMMYPIN = Pin(PORTX, 0);
constexpr Pin PIN_ADC_CTRL_1 = C5;
constexpr Pin PIN_ADC_CTRL_2 = C4;
constexpr Pin PIN_ADC_CTRL_3 = C3;
constexpr Pin PIN_ADC_CTRL_4 = C2;
constexpr Pin PIN_ADC_CTRL_5 = C6;
constexpr Pin PIN_ADC_CTRL_6 = C7;
constexpr Pin PIN_ADC_CTRL_7 = C8;
constexpr Pin PIN_ADC_CTRL_8 = C9;
constexpr Pin PIN_ADC_CTRL_9 = A2;
constexpr Pin PIN_ADC_CTRL_10 = A3;
constexpr Pin PIN_ADC_CTRL_11 = D9;
constexpr Pin PIN_ADC_CTRL_12 = D8;
constexpr Pin PIN_USER_LED = Pin(PORTC, 7);

/** This is an adapter for the new Pin mapping system in the namespace so that
* GetPin still works. If GetPin is removed (i.e. the next major version), this should also be removed
*/
constexpr Pin kPinMap[4][10]
= {{A1, A2, A3, A4, A5, A6, A7, A8, A9, A10}, // Bank A
{B1, B2, B3, B4, B5, B6, B7, B8, B9, B10}, // Bank B
{C1, C2, C3, C4, C5, C6, C7, C8, C9, C10}, // Bank C
{D1, D2, D3, D4, D5, D6, D7, D8, D9, D10}}; // Bank D

/** outside of class static buffer(s) for DMA access */
uint16_t DMA_BUFFER_MEM_SECTION dsy_patch_sm_dac_buffer[2][48];
Expand Down Expand Up @@ -246,12 +159,12 @@ namespace patch_sm
QSPIHandle::Config qspi_config;
qspi_config.device = QSPIHandle::Config::Device::IS25LP064A;
qspi_config.mode = QSPIHandle::Config::Mode::MEMORY_MAPPED;
qspi_config.pin_config.io0 = {DSY_GPIOF, 8};
qspi_config.pin_config.io1 = {DSY_GPIOF, 9};
qspi_config.pin_config.io2 = {DSY_GPIOF, 7};
qspi_config.pin_config.io3 = {DSY_GPIOF, 6};
qspi_config.pin_config.clk = {DSY_GPIOF, 10};
qspi_config.pin_config.ncs = {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);
qspi.Init(qspi_config);
}
/** Audio */
Expand All @@ -264,19 +177,19 @@ namespace patch_sm
sai_config.b_sync = SaiHandle::Config::Sync::SLAVE;
sai_config.a_dir = SaiHandle::Config::Direction::RECEIVE;
sai_config.b_dir = SaiHandle::Config::Direction::TRANSMIT;
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.sa = {DSY_GPIOE, 6};
sai_config.pin_config.sb = {DSY_GPIOE, 3};
sai_config.pin_config.fs = Pin(PORTE, 4);
sai_config.pin_config.mclk = Pin(PORTE, 2);
sai_config.pin_config.sck = Pin(PORTE, 5);
sai_config.pin_config.sa = Pin(PORTE, 6);
sai_config.pin_config.sb = Pin(PORTE, 3);
SaiHandle sai_1_handle;
sai_1_handle.Init(sai_config);
I2CHandle::Config i2c_cfg;
i2c_cfg.periph = I2CHandle::Config::Peripheral::I2C_2;
i2c_cfg.mode = I2CHandle::Config::Mode::I2C_MASTER;
i2c_cfg.speed = I2CHandle::Config::Speed::I2C_400KHZ;
i2c_cfg.pin_config.scl = {DSY_GPIOB, 10};
i2c_cfg.pin_config.sda = {DSY_GPIOB, 11};
i2c_cfg.pin_config.scl = Pin(PORTB, 10);
i2c_cfg.pin_config.sda = Pin(PORTB, 11);
I2CHandle i2c2;
i2c2.Init(i2c_cfg);
codec.Init(i2c2);
Expand All @@ -291,7 +204,7 @@ namespace patch_sm
/** ADC Init */
AdcChannelConfig adc_config[ADC_LAST];
/** Order of pins to match enum expectations */
dsy_gpio_pin adc_pins[] = {
constexpr Pin adc_pins[] = {
PIN_ADC_CTRL_1,
PIN_ADC_CTRL_2,
PIN_ADC_CTRL_3,
Expand Down Expand Up @@ -326,8 +239,8 @@ namespace patch_sm
user_led.pin = PIN_USER_LED;
dsy_gpio_init(&user_led);
//gate_in_1.Init((dsy_gpio_pin *)&DaisyPatchSM::B10);
gate_in_1.Init((dsy_gpio_pin *)&B10);
gate_in_2.Init((dsy_gpio_pin *)&B9);
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;
Expand Down Expand Up @@ -368,7 +281,10 @@ namespace patch_sm
audio.ChangeCallback(cb);
}

void DaisyPatchSM::StopAudio() { audio.Stop(); }
void DaisyPatchSM::StopAudio()
{
audio.Stop();
}

void DaisyPatchSM::SetAudioBlockSize(size_t size)
{
Expand Down Expand Up @@ -424,13 +340,25 @@ namespace patch_sm
return audio.GetConfig().blocksize;
}

float DaisyPatchSM::AudioSampleRate() { return audio.GetSampleRate(); }
float DaisyPatchSM::AudioSampleRate()
{
return audio.GetSampleRate();
}

float DaisyPatchSM::AudioCallbackRate() { return callback_rate_; }
float DaisyPatchSM::AudioCallbackRate()
{
return callback_rate_;
}

void DaisyPatchSM::StartAdc() { adc.Start(); }
void DaisyPatchSM::StartAdc()
{
adc.Start();
}

void DaisyPatchSM::StopAdc() { adc.Stop(); }
void DaisyPatchSM::StopAdc()
{
adc.Stop();
}

void DaisyPatchSM::ProcessAnalogControls()
{
Expand All @@ -442,7 +370,10 @@ namespace patch_sm

void DaisyPatchSM::ProcessDigitalControls() {}

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

dsy_gpio_pin DaisyPatchSM::GetPin(const PinBank bank, const int idx)
{
Expand All @@ -457,14 +388,20 @@ namespace patch_sm
pimpl_->StartDac(callback);
}

void DaisyPatchSM::StopDac() { pimpl_->StopDac(); }
void DaisyPatchSM::StopDac()
{
pimpl_->StopDac();
}

void DaisyPatchSM::WriteCvOut(const int channel, float voltage)
{
pimpl_->WriteCvOut(channel, voltage);
}

void DaisyPatchSM::SetLed(bool state) { dsy_gpio_write(&user_led, state); }
void DaisyPatchSM::SetLed(bool state)
{
dsy_gpio_write(&user_led, state);
}

bool DaisyPatchSM::ValidateSDRAM()
{
Expand Down
58 changes: 47 additions & 11 deletions src/daisy_patch_sm.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ namespace patch_sm
*
* \param bank should be one of the PinBank options above
* \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);

Expand Down Expand Up @@ -255,17 +256,6 @@ namespace patch_sm
GateIn gate_in_1, gate_in_2;
dsy_gpio gate_out_1, gate_out_2;

/** Pin Accessors for the DaisyPatchSM hardware
* Used for initializing various GPIO, etc.
*/
static const dsy_gpio_pin A1, A2, A3, A4, A5;
static const dsy_gpio_pin A6, A7, A8, A9, A10;
static const dsy_gpio_pin B1, B2, B3, B4, B5;
static const dsy_gpio_pin B6, B7, B8, B9, B10;
static const dsy_gpio_pin C1, C2, C3, C4, C5;
static const dsy_gpio_pin C6, C7, C8, C9, C10;
static const dsy_gpio_pin D1, D2, D3, D4, D5;
static const dsy_gpio_pin D6, D7, D8, D9, D10;
class Impl;

private:
Expand All @@ -277,6 +267,52 @@ namespace patch_sm
Impl* pimpl_;
};

/** Pin Accessors for the DaisyPatchSM hardware
* Used for initializing various GPIO, etc.
*/
constexpr Pin A1 = Pin(PORTX, 0); /**< A1 - -12V Power Input */
constexpr Pin A2 = Pin(PORTA, 1); /**< A2 - UART1 Rx */
constexpr Pin A3 = Pin(PORTA, 0); /**< A3 - UART1 Tx */
constexpr Pin A4 = Pin(PORTX, 0); /**< A4 - GND */
constexpr Pin A5 = Pin(PORTX, 0); /**< A5 - +12V Power Input */
constexpr Pin A6 = Pin(PORTX, 0); /**< A6 - +5V Power Output */
constexpr Pin A7 = Pin(PORTX, 0); /**< A7 - GND */
constexpr Pin A8 = Pin(PORTB, 14); /**< A8 - USB DM */
constexpr Pin A9 = Pin(PORTB, 15); /**< A9 - USB DP */
constexpr Pin A10 = Pin(PORTX, 0); /**< A10 - +3V3 Power Output */

constexpr Pin B1 = Pin(PORTX, 0); /**< B1 - Audio Out Right */
constexpr Pin B2 = Pin(PORTX, 0); /**< B2 - Audio Out Left*/
constexpr Pin B3 = Pin(PORTX, 0); /**< B3 - Audio In Right */
constexpr Pin B4 = Pin(PORTX, 0); /**< B4 - Audio In Left */
constexpr Pin B5 = Pin(PORTC, 14); /**< B5 - GATE OUT 1 */
constexpr Pin B6 = Pin(PORTC, 13); /**< B6 - GATE OUT 2 */
constexpr Pin B7 = Pin(PORTB, 8); /**< B7 - I2C1 SCL */
constexpr Pin B8 = Pin(PORTB, 9); /**< B8 - I2C1 SDA */
constexpr Pin B9 = Pin(PORTG, 14); /**< B9 - GATE IN 2 */
constexpr Pin B10 = Pin(PORTG, 13); /**< B10 - GATE IN 1 */

constexpr Pin C1 = Pin(PORTA, 5); /**< C1 - CV Out 2 */
constexpr Pin C2 = Pin(PORTA, 7); /**< C2 - CV In 4 */
constexpr Pin C3 = Pin(PORTA, 2); /**< C3 - CV In 3 */
constexpr Pin C4 = Pin(PORTA, 6); /**< C4 - CV In 2 */
constexpr Pin C5 = Pin(PORTA, 3); /**< C5 - CV In 1 */
constexpr Pin C6 = Pin(PORTB, 1); /**< C6 - CV In 5 */
constexpr Pin C7 = Pin(PORTC, 4); /**< C7 - CV In 6 */
constexpr Pin C8 = Pin(PORTC, 0); /**< C8 - CV In 7 */
constexpr Pin C9 = Pin(PORTC, 1); /**< C9 - CV In 8 */
constexpr Pin C10 = Pin(PORTA, 4); /**< C10 - CV Out 1 */

constexpr Pin D1 = Pin(PORTB, 4); /**< D1 - SPI2 CS */
constexpr Pin D2 = Pin(PORTC, 11); /**< D2 - SDMMC D3 */
constexpr Pin D3 = Pin(PORTC, 10); /**< D3 - SDMMC D2*/
constexpr Pin D4 = Pin(PORTC, 9); /**< D4 - SDMMC D1*/
constexpr Pin D5 = Pin(PORTC, 8); /**< D5 - SDMMC D0 */
constexpr Pin D6 = Pin(PORTC, 12); /**< D6 - SDMMC CK */
constexpr Pin D7 = Pin(PORTD, 2); /**< D7 - SDMMC CMD */
constexpr Pin D8 = Pin(PORTC, 2); /**< D8 - SPI2 MISO */
constexpr Pin D9 = Pin(PORTC, 3); /**< D9 - SPI2 MOSI */
constexpr Pin D10 = Pin(PORTD, 3); /**< D10 - SPI2 SCK */
} // namespace patch_sm

} // namespace daisy

0 comments on commit 5c30e60

Please sign in to comment.