Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8609

General • Re: Using DMA to output to a parallal bus (GPIOs)?

$
0
0
Spent a small bit of time on this tonight, and here's more concrete code. It's fragments from the full project but good enough for examples I think:

Setting up the GPIO pins:

Code:

void init_gpio() {// Setup GPIOs  // SIO, Output  // GPIO 00-15 are all connected to the DAC  // 18 and 22 are output enable for the level shifts  // Wrong endian yo  gpio_set_function_masked(0b00000000010001001111111111111111, GPIO_FUNC_SIO);  // DAC  // UARTs  // GPIO 16-17, MIDI on UART0, (will disable USB serial)  //gpio_set_function_masked(XXXX, GPIO_FUNC_UART);  // GPIO on 20-21, UART1 to TI UART  gpio_set_function_masked(0b00000000001100000000000000000000, GPIO_FUNC_UART);// Disable pullup/downs for all the pins going to the TI UARTfor(uint8_t count = 0 ; count < 15; ++count)gpio_disable_pulls(count);// Disable pullups for level shiftersgpio_disable_pulls(GPIO_UART_SHIFTER);gpio_disable_pulls(GPIO_MIDI_SHIFTER);  // Enable UART level shifter  gpio_put(GPIO_UART_SHIFTER, true);  // Disable MIDI level shifter (while USB UART is enabled)  gpio_put(GPIO_MIDI_SHIFTER, false);
Then the stuff that will end up doing DAC thangs:

Code:

void Audio::init() {// Clear all registers in DACgpio_put(DAC_GPIO_CLEAR, false);sleep_ms(10);gpio_put(DAC_GPIO_CLEAR, true);// Set LDAC low since we are updating each DAC channel asyncgpio_put(DAC_GPIO_LDAC, false);}// Steps:// Enable writing to DAC // Combine address and data into 32-bit payload// Output payload// Toggle write enablevoid Audio::writeToDAC(uint8_t voice, uint8_t data) {// Shift voice and data to the right spotsuint32_t value = ((uint32_t)data << 8) | ((uint32_t)voice << 3);// Enable writesgpio_put(DAC_GPIO_WE, false);// Write datagpio_put_masked(DAC_WRITE_MASK, value);// Disable (Apply) writesgpio_put(DAC_GPIO_WE, true);}

Statistics: Posted by m00dawg — Sat Dec 13, 2025 5:22 am



Viewing all articles
Browse latest Browse all 8609

Trending Articles