|
// -------------------------------------------------- // |
|
// This file is autogenerated by pioasm; do not edit! // |
|
// -------------------------------------------------- // |
|
|
|
#pragma once |
|
|
|
#if !PICO_NO_HARDWARE |
|
#include "hardware/pio.h" |
|
#endif |
|
|
|
// ------- // |
|
// uart_tx // |
|
// ------- // |
|
|
|
#define uart_tx_wrap_target 0 |
|
#define uart_tx_wrap 11 |
|
|
|
static const uint16_t uart_tx_program_instructions[] = { |
|
// .wrap_target |
|
0x80a0, // 0: pull block |
|
0xa103, // 1: mov pins, null [1] |
|
0x6108, // 2: out pins, 8 [1] |
|
0x6108, // 3: out pins, 8 [1] |
|
0x6108, // 4: out pins, 8 [1] |
|
0x6008, // 5: out pins, 8 |
|
0x80a0, // 6: pull block |
|
0x6108, // 7: out pins, 8 [1] |
|
0x6108, // 8: out pins, 8 [1] |
|
0x6108, // 9: out pins, 8 [1] |
|
0x6108, // 10: out pins, 8 [1] |
|
0xa00b, // 11: mov pins, !null |
|
// .wrap |
|
}; |
|
|
|
#if !PICO_NO_HARDWARE |
|
static const struct pio_program uart_tx_program = { |
|
.instructions = uart_tx_program_instructions, |
|
.length = 12, |
|
.origin = -1, |
|
}; |
|
|
|
static inline pio_sm_config uart_tx_program_get_default_config(uint offset) { |
|
pio_sm_config c = pio_get_default_sm_config(); |
|
sm_config_set_wrap(&c, offset + uart_tx_wrap_target, offset + uart_tx_wrap); |
|
return c; |
|
} |
|
|
|
static inline void uart_tx_program_init(PIO pio, uint sm, uint offset, uint pin, uint baud) { |
|
const int PIN_COUNT = 8; |
|
const int PIN_MASK = 0xFF; |
|
// the number of PIO cycles that it takes to output a single bit |
|
const uint cycles_per_bit = 2; |
|
// the clock divider (number of CPU cycles that each PIO cycle takes) |
|
float div = (float)clock_get_hz(clk_sys) / (baud * cycles_per_bit); |
|
// initialize the pins to high indicating the stop bit |
|
pio_sm_set_set_pins(pio, sm, pin, PIN_COUNT); |
|
pio_sm_set_pindirs_with_mask(pio, sm, 0xFFFFFFFF, PIN_MASK << pin); |
|
pio_sm_set_pins_with_mask(pio, sm, 0xFFFFFFFF, PIN_MASK << pin); |
|
for (int i = 0; i < PIN_COUNT; i++) { |
|
pio_gpio_init(pio, pin + i); |
|
} |
|
pio_sm_config c = uart_tx_program_get_default_config(offset); |
|
sm_config_set_out_shift(&c, true, false, 32); // shift to right, no autopull |
|
sm_config_set_out_pins(&c, pin, PIN_COUNT); // Set 8 pins starting at `pin` |
|
sm_config_set_set_pins(&c, pin, PIN_COUNT); // Set 8 pins starting at `pin` |
|
sm_config_set_clkdiv(&c, div); |
|
pio_sm_init(pio, sm, offset, &c); // Load config |
|
pio_sm_set_enabled(pio, sm, true); // Start state machine |
|
} |
|
static inline void uart_tx_program_putc(PIO pio, uint sm, uint32_t b1, uint32_t b2) { |
|
pio_sm_put_blocking(pio, sm, b1); |
|
pio_sm_put_blocking(pio, sm, b2); |
|
} |
|
|
|
#endif |