80 lines
2.1 KiB
C
80 lines
2.1 KiB
C
|
|
#include <hardware/gpio.h>
|
|
#include <hardware/pio.h>
|
|
#include <pico/time.h>
|
|
|
|
#include "tool78_defs.h"
|
|
#include "tool78_hw_helpers.h"
|
|
|
|
#include "tool78.pio.h"
|
|
|
|
#include "tool78_hw.h"
|
|
|
|
static struct tool78_pio_vars vars;
|
|
|
|
static int trl78_uart2_send(int len, const uint8_t* data, int32_t timeout_us);
|
|
|
|
static bool trl78_uart2_init(void) {
|
|
if (!tool78_hw_init_help(&tool78_uart_tx_program, &tool78_uart_rx_program,
|
|
&vars)) return false;
|
|
|
|
vars.exclusive = false;
|
|
vars.bitswap = true;
|
|
|
|
tool78_entryseq_rl78(tool78_entry_rl78_uart2);
|
|
|
|
// init TX first on TOOL0 for stuff
|
|
tool78_uart_tx_program_init(PINOUT_TOOL78_PIO, vars.smtx, vars.txoff,
|
|
PINOUT_TOOL78_RL78_TOOL0, 115200, true);
|
|
|
|
uint8_t byte = (uint8_t)tool78_entry_rl78_uart2;
|
|
trl78_uart2_send(1, &byte, -1);
|
|
|
|
busy_wait_us_32(70); // tMB
|
|
|
|
// now init the real UART lines
|
|
tool78_uart_tx_program_init(PINOUT_TOOL78_PIO, vars.smtx, vars.txoff,
|
|
PINOUT_TOOL78_RL78_TX, 115200, true);
|
|
tool78_uart_rx_program_init(PINOUT_TOOL78_PIO, vars.smrx, vars.rxoff,
|
|
PINOUT_TOOL78_RL78_RX, 115200, true);
|
|
gpio_set_function(PINOUT_TOOL78_RL78_TOOL0, GPIO_FUNC_SIO);
|
|
|
|
// now a baudrate set command needs to be sent, but we leave that to the
|
|
// upper (command processing) layer as it has to know about those timings
|
|
// anyway
|
|
|
|
return true; // all is well!
|
|
}
|
|
static void trl78_uart2_deinit(void) {
|
|
tool78_hw_deinit_help(&tool78_uart_tx_program, &tool78_uart_rx_program,
|
|
&vars);
|
|
|
|
tool78_deinit_rl78();
|
|
}
|
|
|
|
static int trl78_uart2_has_available(void) {
|
|
return tool78_hw_has_available_help(&vars);
|
|
}
|
|
|
|
static int trl78_uart2_recv(int len, uint8_t* data, int32_t timeout_us) {
|
|
return tool78_hw_help_recv(&vars, len, data, timeout_us);
|
|
}
|
|
static int trl78_uart2_send(int len, const uint8_t* data, int32_t timeout_us) {
|
|
// TODO: tDR changes after first baudrate set
|
|
return tool78_hw_help_send(&vars, 190/*inter-byte delay (us) tDR = 90/8M s */,
|
|
len, data, timeout_us);
|
|
}
|
|
|
|
struct tool78_hw tool78_hw_rl78_uart2 = {
|
|
.target = tool78rl_uart2,
|
|
|
|
.init = trl78_uart2_init,
|
|
.deinit = trl78_uart2_deinit,
|
|
|
|
.has_available = trl78_uart2_has_available,
|
|
|
|
.recv = trl78_uart2_recv,
|
|
.send = trl78_uart2_send
|
|
};
|
|
|