diff options
author | James McKenzie <git@madingley.org> | 2015-08-02 23:37:49 +0100 |
---|---|---|
committer | James McKenzie <git@madingley.org> | 2015-08-02 23:37:49 +0100 |
commit | ff7e2824011f787acd730ac788b06610c6e40132 (patch) | |
tree | 1e9ab49d2f1b5513e93f9df324e4fc72bfefc175 | |
parent | 39687aa7c7b138d2a1ce2551f2400bade3b1a6fb (diff) | |
download | candlestick-ff7e2824011f787acd730ac788b06610c6e40132.tar.gz candlestick-ff7e2824011f787acd730ac788b06610c6e40132.tar.bz2 candlestick-ff7e2824011f787acd730ac788b06610c6e40132.zip |
fish
-rw-r--r-- | .gitignore | 7 | ||||
-rw-r--r-- | app/Makefile | 2 | ||||
-rw-r--r-- | app/crypto.ld | 15 | ||||
-rw-r--r-- | app/i2c1.c (renamed from app/i2c.c) | 48 | ||||
-rw-r--r-- | app/i2c2.c | 132 | ||||
-rw-r--r-- | app/lcd.c | 24 | ||||
-rw-r--r-- | app/main.c | 8 | ||||
-rw-r--r-- | app/prototypes.h | 12 | ||||
-rw-r--r-- | boot/usbdfu.ld | 6 |
9 files changed, 201 insertions, 53 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e530e6a --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.map +*.d +*.o +*~ +*.elf +*.hex +*.dfu diff --git a/app/Makefile b/app/Makefile index 7b4e978..3bdb8d4 100644 --- a/app/Makefile +++ b/app/Makefile @@ -24,7 +24,7 @@ PROG=crypto V=1 default: ${PROG}.elf -CSRCS=dfu.c crypto.c main.c usb.c led.c ticker.c i2c.c lcd.c +CSRCS=dfu.c crypto.c main.c usb.c led.c ticker.c i2c1.c i2c2.c lcd.c keypad.c BINARY = ${PROG} diff --git a/app/crypto.ld b/app/crypto.ld index b36fefa..a2d5a9c 100644 --- a/app/crypto.ld +++ b/app/crypto.ld @@ -17,13 +17,13 @@ * along with this library. If not, see <http://www.gnu.org/licenses/>. */ -/* Linker script for STM32F101C8T6, 64K flash, 20K RAM). */ +/* Linker script for Olimex STM32-H103 (STM32F103RBT6, 128K flash, 20K RAM). */ /* Define memory regions. */ MEMORY { - rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K - ram (rwx) : ORIGIN = 0x20000000, LENGTH = 10K + rom (rx) : ORIGIN = 0x08002000, LENGTH = 120K + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K } /* Include the common ld script. */ @@ -31,10 +31,13 @@ INCLUDE libopencm3_stm32f1.ld dfu_shared_location = ORIGIN(ram) + LENGTH(ram) - 1024; +/* PROVIDE(_stack = dfu_shared_location ); */ + SECTIONS { - .dfu_shared dfu_shared_location :{ - dfu_flag = .; - } + .dfu_shared dfu_shared_location :{ + dfu_flag = .; + } } + @@ -9,7 +9,7 @@ #define I2C_BB_DELAY do { delay_us(1); } while (0) int -i2c_bb (int scl, int sda) +i2c1_bb (int scl, int sda) { if (scl) gpio_set (GPIO_SCL, SCL); @@ -26,62 +26,62 @@ i2c_bb (int scl, int sda) void -i2c_bb_start (void) +i2c1_bb_start (void) { - i2c_bb (1, 1); + i2c1_bb (1, 1); I2C_BB_DELAY; - i2c_bb (1, 0); + i2c1_bb (1, 0); I2C_BB_DELAY; - i2c_bb (0, 0); + i2c1_bb (0, 0); I2C_BB_DELAY; } void -i2c_bb_stop (void) +i2c1_bb_stop (void) { - i2c_bb (0, 0); + i2c1_bb (0, 0); I2C_BB_DELAY; - i2c_bb (1, 0); + i2c1_bb (1, 0); I2C_BB_DELAY; - i2c_bb (1, 1); + i2c1_bb (1, 1); I2C_BB_DELAY; } int -i2c_bb_send_data (uint8_t v) +i2c1_bb_send_data (uint8_t v) { int c; for (c = 0x80; c; c >>= 1) { - i2c_bb (0, c & v); + i2c1_bb (0, c & v); I2C_BB_DELAY; - i2c_bb (1, c & v); + i2c1_bb (1, c & v); I2C_BB_DELAY; - i2c_bb (0, c & v); + i2c1_bb (0, c & v); I2C_BB_DELAY; } - i2c_bb (0, 1); + i2c1_bb (0, 1); I2C_BB_DELAY; - i2c_bb (1, 1); + i2c1_bb (1, 1); I2C_BB_DELAY; - c = i2c_bb (1, 1); - i2c_bb (0, 1); + c = i2c1_bb (1, 1); + i2c1_bb (0, 1); return c; } int -i2c_bb_start_transaction (uint8_t a, int wnr) +i2c1_bb_start_transaction (uint8_t a, int wnr) { int ret; - i2c_bb_start (); - ret = i2c_bb_send_data (a << 1 | ! !(wnr)); + i2c1_bb_start (); + ret = i2c1_bb_send_data (a << 1 | ! !(wnr)); return ret; @@ -89,7 +89,7 @@ i2c_bb_start_transaction (uint8_t a, int wnr) #if 0 void -i2c_bb_scan (void) +i2c1_bb_scan (void) { int i, r; @@ -118,15 +118,15 @@ i2c_bb_scan (void) #endif void -i2c_bb_init (void) +i2c1_bb_init (void) { gpio_set_mode (GPIO_SCL, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, SCL); gpio_set_mode (GPIO_SDA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, SDA); - i2c_bb_start (); - i2c_bb_stop (); + i2c1_bb_start (); + i2c1_bb_stop (); } diff --git a/app/i2c2.c b/app/i2c2.c new file mode 100644 index 0000000..77701cc --- /dev/null +++ b/app/i2c2.c @@ -0,0 +1,132 @@ +#include "project.h" + + +#define GPIO_SCL GPIOA +#define GPIO_SDA GPIOB +#define SCL GPIO5 +#define SDA GPIO11 + +#define I2C_BB_DELAY do { delay_us(1); } while (0) + +int +i2c2_bb (int scl, int sda) +{ + if (scl) + gpio_set (GPIO_SCL, SCL); + else + gpio_clear (GPIO_SCL, SCL); + if (sda) + gpio_set (GPIO_SDA, SDA); + else + gpio_clear (GPIO_SDA, SDA); + + return ! !(gpio_get (GPIO_SDA, SDA) & SDA); + +} + + +void +i2c2_bb_start (void) +{ + i2c2_bb (1, 1); + I2C_BB_DELAY; + i2c2_bb (1, 0); + I2C_BB_DELAY; + i2c2_bb (0, 0); + I2C_BB_DELAY; +} + + +void +i2c2_bb_stop (void) +{ + i2c2_bb (0, 0); + I2C_BB_DELAY; + i2c2_bb (1, 0); + I2C_BB_DELAY; + i2c2_bb (1, 1); + I2C_BB_DELAY; +} + +int +i2c2_bb_send_data (uint8_t v) +{ + int c; + + + for (c = 0x80; c; c >>= 1) + { + i2c2_bb (0, c & v); + I2C_BB_DELAY; + i2c2_bb (1, c & v); + I2C_BB_DELAY; + i2c2_bb (0, c & v); + I2C_BB_DELAY; + } + + i2c2_bb (0, 1); + I2C_BB_DELAY; + i2c2_bb (1, 1); + I2C_BB_DELAY; + c = i2c2_bb (1, 1); + i2c2_bb (0, 1); + + return c; +} + + +int +i2c2_bb_start_transaction (uint8_t a, int wnr) +{ + int ret; + + i2c2_bb_start (); + ret = i2c2_bb_send_data (a << 1 | ! !(wnr)); + + + return ret; +} + +#if 0 +void +i2c2_bb_scan (void) +{ + int i, r; + + return; + i2cp_reset (); + + printf ("Probing bus\r\n"); + for (i = 0; i < 128; ++i) + { + while (i2cp_lock ()); + i2cp_start (); + i2cp_abort_start (); + i2cp_stop (); + i2cp_abort_stop (); + r = i2cp_start_transaction (i, I2C_WRITE); + i2cp_stop (); + i2cp_unlock (); + if (!r) + printf ("Found device at address 0x%x\r\n", i); + usart1_drain (); + } + printf ("Done\r\n"); + i2cp_reset (); + +} +#endif + +void +i2c2_bb_init (void) +{ + gpio_set_mode (GPIO_SCL, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_OPENDRAIN, SCL); + gpio_set_mode (GPIO_SDA, GPIO_MODE_OUTPUT_50_MHZ, + GPIO_CNF_OUTPUT_OPENDRAIN, SDA); + + i2c2_bb_start (); + i2c2_bb_stop (); + + +} @@ -52,9 +52,9 @@ clock_nibble (uint8_t n) { if (backlight) n |= LINE_BACKLIGHT; - i2c_bb_send_data (n); - i2c_bb_send_data (LINE_EN | n); - i2c_bb_send_data (n); + i2c1_bb_send_data (n); + i2c1_bb_send_data (LINE_EN | n); + i2c1_bb_send_data (n); } @@ -92,9 +92,9 @@ send_command (uint8_t c) static void send_one_command (uint8_t cmd, int delay) { - i2c_bb_start_transaction (PCF8574_I2C_ADDRESS, I2C_WRITE); + i2c1_bb_start_transaction (PCF8574_I2C_ADDRESS, I2C_WRITE); send_command (cmd); - i2c_bb_stop (); + i2c1_bb_stop (); if (delay) delay_ms (delay); } @@ -150,7 +150,7 @@ lcd_refresh (void) int addr; - i2c_bb_start_transaction (PCF8574_I2C_ADDRESS, I2C_WRITE); + i2c1_bb_start_transaction (PCF8574_I2C_ADDRESS, I2C_WRITE); for (r = 0; r < LCD_H; ++r) @@ -178,7 +178,7 @@ lcd_refresh (void) } } - i2c_bb_stop (); + i2c1_bb_stop (); } void @@ -299,9 +299,9 @@ lcd_backlight (int i) { backlight = i; - i2c_bb_start_transaction (PCF8574_I2C_ADDRESS, I2C_WRITE); - i2c_bb_send_data (backlight ? LINE_BACKLIGHT : 0); - i2c_bb_stop (); + i2c1_bb_start_transaction (PCF8574_I2C_ADDRESS, I2C_WRITE); + i2c1_bb_send_data (backlight ? LINE_BACKLIGHT : 0); + i2c1_bb_stop (); } @@ -312,7 +312,7 @@ lcd_backlight (int i) void lcd_reset (void) { - i2c_bb_start_transaction (PCF8574_I2C_ADDRESS, I2C_WRITE); + i2c1_bb_start_transaction (PCF8574_I2C_ADDRESS, I2C_WRITE); clock_nibble (0x30); delay_ms (5); clock_nibble (0x30); @@ -322,7 +322,7 @@ lcd_reset (void) clock_nibble (0x20); send_command (LCD_FUNC | LCD_FUNC_4BIT | LCD_FUNC_2ROWS | LCD_FUNC_5X7); - i2c_bb_stop (); + i2c1_bb_stop (); on (); cls (); } @@ -17,15 +17,21 @@ main (void) ticker_init (); led_init (); - i2c_bb_init (); + i2c1_bb_init (); lcd_init (); + i2c2_bb_init (); + keypad_init(); + lcd_backlight (1); + +#if 0 { char buf[16]; sprintf(buf,"%x",dfu_flag); lcd_write(buf,0,1); } +#endif lcd_write ("hello world", 0, 0); diff --git a/app/prototypes.h b/app/prototypes.h index f977d61..78a0e8b 100644 --- a/app/prototypes.h +++ b/app/prototypes.h @@ -31,12 +31,12 @@ extern void delay_ms(uint32_t d); extern int timed_out(uint32_t then, unsigned int ms); extern void ticker_init(void); /* i2c.c */ -extern int i2c_bb(int scl, int sda); -extern void i2c_bb_start(void); -extern void i2c_bb_stop(void); -extern int i2c_bb_send_data(uint8_t v); -extern int i2c_bb_start_transaction(uint8_t a, int wnr); -extern void i2c_bb_init(void); +extern int i2c1_bb(int scl, int sda); +extern void i2c1_bb_start(void); +extern void i2c1_bb_stop(void); +extern int i2c1_bb_send_data(uint8_t v); +extern int i2c1_bb_start_transaction(uint8_t a, int wnr); +extern void i2c1_bb_init(void); /* lcd.c */ extern uint8_t fb[2][16]; extern uint8_t shadow[2][16]; diff --git a/boot/usbdfu.ld b/boot/usbdfu.ld index b36fefa..8680dc9 100644 --- a/boot/usbdfu.ld +++ b/boot/usbdfu.ld @@ -17,13 +17,13 @@ * along with this library. If not, see <http://www.gnu.org/licenses/>. */ -/* Linker script for STM32F101C8T6, 64K flash, 20K RAM). */ +/* Linker script for Olimex STM32-H103 (STM32F103RBT6, 128K flash, 20K RAM). */ /* Define memory regions. */ MEMORY { - rom (rx) : ORIGIN = 0x08000000, LENGTH = 64K - ram (rwx) : ORIGIN = 0x20000000, LENGTH = 10K + rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K + ram (rwx) : ORIGIN = 0x20000000, LENGTH = 20K } /* Include the common ld script. */ |