aboutsummaryrefslogtreecommitdiff
path: root/system-clock/src
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2018-01-15 15:49:13 -0700
committerJosh Rahm <joshuarahm@gmail.com>2018-01-15 15:49:13 -0700
commit6d3197d768bf13c1402c1305050ea355f8c79fec (patch)
tree78f9e728e57746363fd1f12f8bc3c5fbcc80a2d1 /system-clock/src
parent67d97164b358ae5c9c0038e58302a6f89c7bb3c5 (diff)
downloadstm32l4-6d3197d768bf13c1402c1305050ea355f8c79fec.tar.gz
stm32l4-6d3197d768bf13c1402c1305050ea355f8c79fec.tar.bz2
stm32l4-6d3197d768bf13c1402c1305050ea355f8c79fec.zip
added spin.*
Diffstat (limited to 'system-clock/src')
-rw-r--r--system-clock/src/spin.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/system-clock/src/spin.c b/system-clock/src/spin.c
new file mode 100644
index 0000000..f233054
--- /dev/null
+++ b/system-clock/src/spin.c
@@ -0,0 +1,50 @@
+#include "spin.h"
+#include "gpio.h"
+#include "delay.h"
+
+#define SHORT_DELAY 200000
+#define LONG_DELAY (SHORT_DELAY * 2)
+
+static void flash_bit(
+ gpio_output_pin_t out_pin,
+ uint8_t bit /* 0 => 0, non-zero => 1 */)
+{
+ pin_on(out_pin);
+ if (bit) {
+ delay(LONG_DELAY);
+ } else {
+ delay(SHORT_DELAY);
+ }
+ pin_off(out_pin);
+ delay(SHORT_DELAY);
+}
+
+void spin(uint8_t c)
+{
+ uint8_t code;
+ __IO gpio_port_t* port_b = enable_gpio(GPIO_PORT_B);
+ gpio_output_pin_t pin3 = set_gpio_pin_output(port_b, PIN_3);
+
+ for(;;) {
+ code = c;
+ flash_bit(pin3, code & 0x80);
+ code <<= 1;
+ flash_bit(pin3, code & 0x80);
+ code <<= 1;
+ flash_bit(pin3, code & 0x80);
+ code <<= 1;
+ flash_bit(pin3, code & 0x80);
+
+
+ code <<= 1;
+ flash_bit(pin3, code & 0x80);
+ code <<= 1;
+ flash_bit(pin3, code & 0x80);
+ code <<= 1;
+ flash_bit(pin3, code & 0x80);
+ code <<= 1;
+ flash_bit(pin3, code & 0x80);
+
+ delay(LONG_DELAY * 4);
+ }
+}