aboutsummaryrefslogtreecommitdiff
path: root/src/platforms/native
diff options
context:
space:
mode:
authorGareth McMullin2015-02-28 22:05:10 -0800
committerGareth McMullin2015-02-28 22:05:10 -0800
commit75001a442126e3b42f6f95f1917a7cb33b92d063 (patch)
tree7f18e7d0623ef54afa3a94712d04abfe25e242db /src/platforms/native
parent5d136398e121168c41e1c3488454e02f11afd67b (diff)
Factor Morse code functions out of platform code.
Diffstat (limited to 'src/platforms/native')
-rw-r--r--src/platforms/native/platform.c86
-rw-r--r--src/platforms/native/platform.h3
2 files changed, 5 insertions, 84 deletions
diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c
index 5e5c78c..3e269d9 100644
--- a/src/platforms/native/platform.c
+++ b/src/platforms/native/platform.c
@@ -34,17 +34,14 @@
#include <libopencm3/stm32/f1/adc.h>
#include "jtag_scan.h"
-#include <usbuart.h>
-
-#include <ctype.h>
+#include "usbuart.h"
+#include "morse.h"
uint8_t running_status;
volatile uint32_t timeout_counter;
jmp_buf fatal_error_jmpbuf;
-static void morse_update(void);
-
static void adc_init(void);
/* Pins PB[7:5] are used to detect hardware revision.
@@ -187,83 +184,7 @@ void sys_tick_handler(void)
if(timeout_counter)
timeout_counter--;
- morse_update();
-}
-
-
-/* Morse code patterns and lengths */
-static const struct {
- uint16_t code;
- uint8_t bits;
-} morse_letter[] = {
- { 0b00011101, 8}, // 'A' .-
- { 0b000101010111, 12}, // 'B' -...
- { 0b00010111010111, 14}, // 'C' -.-.
- { 0b0001010111, 10}, // 'D' -..
- { 0b0001, 4}, // 'E' .
- { 0b000101110101, 12}, // 'F' ..-.
- { 0b000101110111, 12}, // 'G' --.
- { 0b0001010101, 10}, // 'H' ....
- { 0b000101, 6}, // 'I' ..
- {0b0001110111011101, 16}, // 'J' .---
- { 0b000111010111, 12}, // 'K' -.-
- { 0b000101011101, 12}, // 'L' .-..
- { 0b0001110111, 10}, // 'M' --
- { 0b00010111, 8}, // 'N' -.
- { 0b00011101110111, 14}, // 'O' ---
- { 0b00010111011101, 14}, // 'P' .--.
- {0b0001110101110111, 16}, // 'Q' --.-
- { 0b0001011101, 10}, // 'R' .-.
- { 0b00010101, 8}, // 'S' ...
- { 0b000111, 6}, // 'T' -
- { 0b0001110101, 10}, // 'U' ..-
- { 0b000111010101, 12}, // 'V' ...-
- { 0b000111011101, 12}, // 'W' .--
- { 0b00011101010111, 14}, // 'X' -..-
- {0b0001110111010111, 16}, // 'Y' -.--
- { 0b00010101110111, 14}, // 'Z' --..
-};
-
-
-const char *morse_msg;
-static const char * volatile morse_ptr;
-static char morse_repeat;
-
-void morse(const char *msg, char repeat)
-{
- morse_msg = morse_ptr = msg;
- morse_repeat = repeat;
- SET_ERROR_STATE(0);
-}
-
-static void morse_update(void)
-{
- static uint16_t code;
- static uint8_t bits;
-
- if(!morse_ptr) return;
-
- if(!bits) {
- char c = *morse_ptr++;
- if(!c) {
- if(morse_repeat) {
- morse_ptr = morse_msg;
- c = *morse_ptr++;
- } else {
- morse_ptr = 0;
- return;
- }
- }
- if((c >= 'A') && (c <= 'Z')) {
- c -= 'A';
- code = morse_letter[c].code;
- bits = morse_letter[c].bits;
- } else {
- code = 0; bits = 4;
- }
- }
- SET_ERROR_STATE(code & 1);
- code >>= 1; bits--;
+ SET_ERROR_STATE(morse_update());
}
static void adc_init(void)
@@ -351,3 +272,4 @@ void setup_vbus_irq(void)
exti15_10_isr();
}
+
diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h
index 81a2a4b..73b6c59 100644
--- a/src/platforms/native/platform.h
+++ b/src/platforms/native/platform.h
@@ -35,6 +35,7 @@
#include <alloca.h>
#include "gdb_packet.h"
+#include "morse.h"
#define INLINE_GPIO
#define CDCACM_PACKET_SIZE 64
@@ -163,7 +164,6 @@ extern volatile uint32_t timeout_counter;
extern jmp_buf fatal_error_jmpbuf;
-extern const char *morse_msg;
#define gpio_set_val(port, pin, val) do { \
if(val) \
@@ -187,7 +187,6 @@ extern const char *morse_msg;
} while (0)
int platform_init(void);
-void morse(const char *msg, char repeat);
const char *platform_target_voltage(void);
int platform_hwversion(void);
void platform_delay(uint32_t delay);