Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding UART glitching #187

Merged
merged 8 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ set(bp5_common
lib/minmea/gps.c
commands/uart/monitor.h
commands/uart/monitor.c
commands/uart/glitch.h
commands/uart/glitch.c

# Half duplex UART
mode/hwhduart.h
Expand Down Expand Up @@ -492,6 +494,7 @@ foreach(revision ${revisions})
#pico_generate_pio_header(${revision} ${CMAKE_CURRENT_LIST_DIR}/pirate/pwm.pio)
pico_generate_pio_header(${revision} ${CMAKE_CURRENT_LIST_DIR}/pirate/onewire_library.pio)
pico_generate_pio_header(${revision} ${CMAKE_CURRENT_LIST_DIR}/lib/pio_pwm/pwm.pio)
pico_generate_pio_header(${revision} ${CMAKE_CURRENT_LIST_DIR}/commands/uart/glitch.pio)

pico_set_program_name(${revision} ${revision})
pico_set_program_version(${revision} "0.1.0")
Expand Down
600 changes: 600 additions & 0 deletions src/commands/uart/glitch.c

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/commands/uart/glitch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef UART_GLITCH
void uart_glitch_handler(struct command_result* res);
#define UART_GLITCH
#endif // UART_GLITCH
50 changes: 50 additions & 0 deletions src/commands/uart/glitch.pio
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
;
;
;

.program uart_glitch

.wrap_target
pull ; get the "on" time of the glitch pulse
mov x OSR ; store it in X
pull ; get the number of edges in the trigger character
mov y OSR ; store it in Y
pull ; get the delay before starting glitch pulse (just hold on for now)

return_loop:
wait 0 pin 0 ; idle state of TX line is high, wait for it to go low
wait 1 pin 0 ; wait for it to go back up
jmp y-- return_loop ; decrement

mov y OSR ; now set the delay time to the y register

delay_loop:
jmp y-- delay_loop ; decrement delay before turning on the output

set pins 1 ; OK, turn it on now

high_loop:
jmp x-- high_loop ; decrement the glitch pulse high time
set pins 0 ; turn it off

.wrap

% c-sdk {
#include "hardware/clocks.h"
static inline void uart_glitch_program_init(PIO pio, uint sm, uint offset, uint glitch_pin, uint tx_pin) {
pio_sm_config c = uart_glitch_program_get_default_config(offset);

sm_config_set_set_pins (&c, glitch_pin, 1);
sm_config_set_in_pins(&c, tx_pin);

pio_gpio_init(pio, glitch_pin);
pio_sm_set_consecutive_pindirs(pio, sm, glitch_pin, 1, true);
pio_sm_set_consecutive_pindirs(pio, sm, tx_pin, 1, false);

float div = (float)clock_get_hz(clk_sys) / (2e7);
sm_config_set_clkdiv(&c, div);

pio_sm_init(pio, sm, offset, &c);
pio_sm_set_enabled(pio, sm, true);
}
%}
6 changes: 6 additions & 0 deletions src/mode/hwuart.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "commands/uart/nmea.h"
#include "commands/uart/bridge.h"
#include "commands/uart/monitor.h"
#include "commands/uart/glitch.h"

static struct _uart_mode_config mode_config;
static struct command_attributes periodic_attributes;
Expand All @@ -39,6 +40,11 @@ const struct _mode_command_struct hwuart_commands[] = {
.description_text=T_UART_CMD_TEST,
.supress_fala_capture=false
},
{ .command="glitch",
.func=&uart_glitch_handler,
.description_text=T_HELP_UART_GLITCH,
.supress_fala_capture=false
},
};
const uint32_t hwuart_commands_count = count_of(hwuart_commands);

Expand Down
2 changes: 2 additions & 0 deletions src/pirate.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ void spi_busy_wait_internal(bool enable, const char *file, int line);

// UART settings
#define M_UART_PORT uart0
#define M_UART_GLITCH_TRG BIO0
#define M_UART_GLITCH_RDY BIO1
#define M_UART_TX BIO4
#define M_UART_RX BIO5
#define M_UART_CTS BIO6
Expand Down
13 changes: 7 additions & 6 deletions src/translation/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ void translation_set(language_idx_t language_idx) {
return;
}

const char* get_current_language_name(void) {
return get_language_name(current_language);
}
language_idx_t get_current_language_idx(void) {
return current_language;
}
const char* get_language_name(language_idx_t language_idx) {
if (language_idx == language_idx_en_us) {
return GET_T(T_CONFIG_LANGUAGE_ENGLISH);
Expand All @@ -118,6 +112,13 @@ const char* get_language_name(language_idx_t language_idx) {
}
}

const char* get_current_language_name(void) {
return get_language_name(current_language);
}
language_idx_t get_current_language_idx(void) {
return current_language;
}

const char* GET_T(enum T_translations index) {
const char* result = NULL;
if (index < T_LAST_ITEM_ALWAYS_AT_THE_END) {
Expand Down
Loading
Loading