diff options
author | root <root@lamia.panaceas.james.local> | 2016-08-23 01:56:47 +0100 |
---|---|---|
committer | root <root@lamia.panaceas.james.local> | 2016-08-23 01:56:47 +0100 |
commit | 7b4848824dcec8c5564bd2b11371f9c5f4a04376 (patch) | |
tree | 7f6e37645e8916da78a2e02ad4c6e83db5866c43 | |
parent | 4dfc42565c2d1f5b900d8d725126bfde886a8423 (diff) | |
download | candlestick-7b4848824dcec8c5564bd2b11371f9c5f4a04376.tar.gz candlestick-7b4848824dcec8c5564bd2b11371f9c5f4a04376.tar.bz2 candlestick-7b4848824dcec8c5564bd2b11371f9c5f4a04376.zip |
working
-rw-r--r-- | app/Makefile | 2 | ||||
-rw-r--r-- | app/dialstr.c | 88 | ||||
-rw-r--r-- | app/gpio.c | 74 | ||||
-rw-r--r-- | app/main.c | 4 | ||||
-rw-r--r-- | app/modem.c | 130 | ||||
-rw-r--r-- | app/project.h | 1 | ||||
-rw-r--r-- | app/prototypes.h | 141 | ||||
-rw-r--r-- | app/ringer.c (renamed from app/buzzer.c) | 35 | ||||
-rw-r--r-- | app/serial.c | 4 | ||||
-rw-r--r-- | app/ticker.c | 2 | ||||
-rw-r--r-- | app/usart.c | 4 | ||||
-rw-r--r-- | doc/BT_SIN_350v1p5.pdf | bin | 0 -> 55872 bytes | |||
-rw-r--r-- | doc/BT_SIN_351v4p6.pdf | bin | 0 -> 173329 bytes | |||
-rw-r--r-- | doc/TTP229.pdf | bin | 132234 -> 0 bytes | |||
-rw-r--r-- | doc/TTP229B-Schematic-Diagram.pdf | bin | 185208 -> 0 bytes |
15 files changed, 369 insertions, 116 deletions
diff --git a/app/Makefile b/app/Makefile index 2a0672b..0a076d2 100644 --- a/app/Makefile +++ b/app/Makefile @@ -25,7 +25,7 @@ PROG=candlestick V=1 default: ${PROG}.elf -CSRCS=dfu.c main.c usb.c led.c ticker.c i2c.c lcd.c cdcacm.c usart.c ring.c serial.c gpio.c console.c buzzer.c modem.c dialstr.c +CSRCS=dfu.c main.c usb.c led.c ticker.c i2c.c lcd.c cdcacm.c usart.c ring.c serial.c gpio.c console.c ringer.c modem.c dialstr.c diff --git a/app/dialstr.c b/app/dialstr.c index 1277a42..26bdfe9 100644 --- a/app/dialstr.c +++ b/app/dialstr.c @@ -11,24 +11,101 @@ dialstr_clear (void) dialstr_ptr = 4; dialstr[dialstr_ptr] = ';'; dialstr[dialstr_ptr + 1] = 0; + dialstr_timeout = 0; } +static void redial(void) +{ + if (in_call) + terminate_call(); + dialstr_timeout = 1; +} + + +static void dialstr_hook(char digit) +{ +switch (digit) { +case '1': + ringer_enable(); + ringer_ring(400); + break; +case '2': + ringer_disable(); + break; +case '0': + for (;;) scb_reset_system(); + break; +} +} + +static void dialstr_call(char digit) +{ +static char cmd[]={'A','T','+','V','T','S','=','"','{','0',',','3','}','"',0}; + +switch (digit) { +case 'R': + redial(); + break; +case 'M': + modem_cmd("AT+CMUT=1"); + break; +case 'U': + modem_cmd("AT+CMUT=0"); + break; +default: + cmd[9]=digit; + modem_cmd(cmd); + break; +} +} + + + void -dialstr_digit (int digit) +dialstr_digit (char digit) { + dialtone_off (); + + printf ("Dialed %c\r\n",digit); + + if (hook) { + dialstr_timeout=0; + dialstr_hook(digit); + return; + } + + if (in_call) { + dialstr_timeout=0; + dialstr_call(digit); + return; + } + + + switch(digit) { + case 'R': + redial(); + break; + + case 'M': + break; + case 'U': + break; + default: + + if (!dialstr_timeout) dialstr_clear (); if (dialstr_ptr >= (sizeof (dialstr) - 2)) - return; + break; - dialstr[dialstr_ptr] = '0' + digit; + dialstr[dialstr_ptr] = digit; dialstr_ptr++; dialstr[dialstr_ptr] = ';'; dialstr[dialstr_ptr + 1] = 0; dialstr_timeout = DIGIT_TIMEOUT; - printf ("Dialstr is now %s\r\n", dialstr + 4); +} } @@ -36,7 +113,8 @@ void dialstr_dial (void) { printf ("Dialing %s\r\n", dialstr + 4); - modem_send (dialstr); + modem_tone(17); + modem_dial (dialstr); } void @@ -1,12 +1,15 @@ #include "project.h" #define DEBOUNCE 10 #define DIAL_BLACKOUT 90 /* (10pps) */ +#define L2_THRESHOLD 1500 -static int hs_poll; -int hook; +static int hs_poll=DEBOUNCE; +int hook=1; static int dial_poll; static int dial_pulse_blackout; static int pulse_count; +static int dial_mute_time; + @@ -26,6 +29,10 @@ exti7_isr (void) if (dial_pulse_blackout) return; dial_pulse_blackout = DIAL_BLACKOUT; + + if ((!pulse_count) && (dial_mute_time>L2_THRESHOLD)) + pulse_count=100; + pulse_count++; } @@ -86,15 +93,24 @@ hs_tick (void) { if (ringing) { - ring_off (); + ringer_off (); answer_call (); } + else + { + ringer_off (); + dialstr_clear (); + dialtone_on (); + } } if (hook) { - ring_off (); + ringer_off (); terminate_call (); + dialstr_clear (); + dialtone_off(); + modem_tone_off(); } @@ -106,6 +122,8 @@ dial_tick (void) { int m; + dial_mute_time++; + if (dial_pulse_blackout) dial_pulse_blackout--; if (!dial_poll) @@ -117,13 +135,46 @@ dial_tick (void) m = ! !gpio_get (GPIOA, GPIO5); - if (m) - return; - if (!pulse_count) + if (m) { + dial_mute_time=0; return; - - dialstr_digit ((pulse_count == 10) ? 0 : pulse_count); - pulse_count = 0; + } + + + switch (pulse_count) { + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + dialstr_digit ('0'+pulse_count); + break; + + case 10: + dialstr_digit ('0'); + break; + case 101: + dialstr_digit ('*'); + break; + case 102: + dialstr_digit ('#'); + break; + case 103: + dialstr_digit ('R'); + break; + case 104: + dialstr_digit ('M'); + break; + case 105: + dialstr_digit ('U'); + break; + } + + pulse_count=0; } @@ -133,7 +184,8 @@ void toggle_fake_hook (void) { fake_hook ^= 1; - hs_poll = DEBOUNCE; + hs_poll = 1; +hs_tick(); } void @@ -30,8 +30,10 @@ main (void) led_init (); usart_init (); + printf("Start of day\r\n"); + gpio_init (); - buzzer_init (); + ringer_init (); modem_init (); diff --git a/app/modem.c b/app/modem.c index b531761..170c7ba 100644 --- a/app/modem.c +++ b/app/modem.c @@ -6,19 +6,24 @@ #define SLEEPY 550 #define BACKOFF 200 +#define N_CMDS 4 + static char modem_buf[BUFFER_SIZE]; -static unsigned modem_ptr = 0; -static char *modem_cmd; +static unsigned modem_ptr; +static char *modem_cmds[N_CMDS]; +static int modem_cmds_ptr; static int timeout; static int sleepy = SLEEPY; +int in_call; +int dialtone; void -modem_send (char *buf) +modem_send (void) { - modem_cmd = buf; + if (!modem_cmds_ptr) return; if (sleepy >= SLEEPY) { @@ -30,29 +35,105 @@ modem_send (char *buf) } sleepy = 0; - printf ("(re)send\r\n"); + printf ("(re)send %s\r\n",modem_cmds[0]); timeout = TIMEOUT; usart2_queue ('\r'); - usart2_tx (modem_cmd, strlen (modem_cmd)); + usart2_tx (modem_cmds[0], strlen (modem_cmds[0])); usart2_queue ('\r'); } +void modem_cmd(char *buf) +{ +if (modem_cmds_ptr==N_CMDS) return; + +modem_cmds[modem_cmds_ptr]=buf; +modem_cmds_ptr++; + +if (modem_cmds_ptr==1) modem_send(); + +} + +void modem_dial (char *buf) { +in_call=1; +modem_cmd(buf); +} + + + +void modem_tone_off() +{ +// modem_cmd ("AT+STTONE=0"); +modem_cmd("AT+SIMTONE=1,400,200,0,10"); +} + +void modem_tone(int i) +{ +static char tone[]={'A','T','+','S','T','T','O','N','E','=','1',',','0','0',',','4','5','0','0','0',0}; + +tone[12]='0'+(i/10); +tone[13]='0'+(i%10); + +modem_cmd(tone); +} + +void modem_tone_nu(void) +{ +modem_cmd("AT+SIMTONE=1,400,200,0,45000"); +} + + void modem_line () { + int i; + printf ("Modem said: %s\r\n", modem_buf); sleepy = 0; - if (!strncmp (modem_buf, "RING", 4)) - ring (4000); - - if (!strncmp (modem_buf, "OK", 2)) + if (!strncmp (modem_buf, "RDY", 4)) { - modem_cmd = NULL; + modem_cmd ("ATZ"); + modem_cmd ("AT+CALM=1"); + modem_cmd ("AT+CLVL=90"); + } + else + if (!strncmp (modem_buf, "RING", 4)) + { + dialstr_clear (); + dialtone = 0; + if (!hook) + { + answer_call (); + } + else + { + ringer_ring (4000); + } + } + else + if (!strncmp (modem_buf, "OK", 2) || !strncmp (modem_buf, "ERROR", 2)) + { + if (modem_cmds_ptr) { + + for (i=1;i<modem_cmds_ptr;++i) { + modem_cmds[i-1]=modem_cmds[i]; + } + modem_cmds_ptr--; + modem_cmds[modem_cmds_ptr]=NULL; + timeout = 0; + + if (modem_cmds_ptr) modem_send(); } + } + else + if (!strncmp (modem_buf, "NO CARRIER", 10)) { + in_call=0; + if (!hook) + modem_tone_nu(); + } } void @@ -83,17 +164,38 @@ void answer_call (void) { printf ("Answering call\r\n"); - modem_send ("ATA"); + dialtone = 0; + modem_cmd ("ATA"); + in_call=1; } void terminate_call (void) { printf ("Terminating any call\r\n"); - modem_send ("ATH0"); + modem_cmd ("ATH0"); + in_call=0; } void +dialtone_on (void) +{ + dialtone = 1; + modem_tone(20); +} + +void +dialtone_off (void) +{ + if (!dialtone) + return; + modem_tone_off(); + + dialtone = 0; +} + + +void modem_tick (void) { @@ -106,7 +208,7 @@ modem_tick (void) if (timeout) return; - modem_send (modem_cmd); + modem_send (); } void diff --git a/app/project.h b/app/project.h index 359b290..6ba8012 100644 --- a/app/project.h +++ b/app/project.h @@ -12,6 +12,7 @@ #include <libopencm3/cm3/systick.h> #include <libopencm3/cm3/nvic.h> #include <libopencm3/cm3/cortex.h> +#include <libopencm3/cm3/scb.h> #include <libopencm3/usb/usbd.h> #include <libopencm3/usb/cdc.h> #include <stm32f101cb_clock.h> diff --git a/app/prototypes.h b/app/prototypes.h index 9fec585..5842d6e 100644 --- a/app/prototypes.h +++ b/app/prototypes.h @@ -1,14 +1,9 @@ /* dfu.c */ extern const struct usb_dfu_descriptor dfu_function; extern const struct usb_interface_descriptor dfu_iface; -extern int dfu_control_request (usbd_device * usbd_dev, - struct usb_setup_data *req, uint8_t ** buf, - uint16_t * len, - int (**complete) (usbd_device * usbd_dev, - struct usb_setup_data * - req)); +extern int dfu_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, int (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req)); /* main.c */ -extern int main (void); +extern int main(void); /* usb.c */ extern const struct usb_device_descriptor dev; extern const struct usb_interface ifaces[]; @@ -16,92 +11,90 @@ extern const struct usb_config_descriptor config; extern usbd_device *usbd_dev; extern int usb_is_suspended; extern int usb_running; -extern void usb_tick (void); -extern int usb_wakeup_host (void); -extern int class_control_request (usbd_device * usbd_dev, - struct usb_setup_data *req, uint8_t ** buf, - uint16_t * len, - int (**complete) (usbd_device * usbd_dev, - struct usb_setup_data * - req)); -extern void usb_set_config (usbd_device * usbd_dev, uint16_t wValue); +extern void usb_tick(void); +extern int usb_wakeup_host(void); +extern int class_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, int (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req)); +extern void usb_set_config(usbd_device *usbd_dev, uint16_t wValue); extern uint8_t usbd_control_buffer[128]; -extern void usb_init (void); -extern void usb_run (void); +extern void usb_init(void); +extern void usb_run(void); /* led.c */ -extern void led_init (void); -extern void led_tick (void); +extern void led_init(void); +extern void led_tick(void); /* ticker.c */ extern volatile uint32_t ticks; -extern void delay_us (uint32_t d); -extern void sys_tick_handler (void); -extern void delay_ms (uint32_t d); -extern int timed_out (uint32_t then, unsigned int ms); -extern void ticker_init (void); +extern void delay_us(uint32_t d); +extern void sys_tick_handler(void); +extern void delay_ms(uint32_t d); +extern int timed_out(uint32_t then, unsigned int ms); +extern void ticker_init(void); /* i2c.c */ /* lcd.c */ /* cdcacm.c */ extern const struct usb_interface_descriptor comm_iface[]; extern const struct usb_interface_descriptor data_iface[]; -extern int cdcacm_control_request (usbd_device * usbd_dev, - struct usb_setup_data *req, uint8_t ** buf, - uint16_t * len, - int (**complete) (usbd_device * usbd_dev, - struct usb_setup_data * - req)); -extern void cdcacm_data_tx (void *buf, size_t len); -extern void cdcacm_data_rx_cb (usbd_device * usbd_dev, uint8_t ep); +extern int cdcacm_control_request(usbd_device *usbd_dev, struct usb_setup_data *req, uint8_t **buf, uint16_t *len, int (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req)); +extern void cdcacm_data_tx(void *buf, size_t len); +extern void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep); /* usart.c */ extern ring_t rx1_ring; extern ring_t tx1_ring; extern ring_t rx2_ring; extern ring_t tx2_ring; -extern void usart1_isr (void); -extern void usart2_isr (void); -extern int _write (int file, char *ptr, int len); -extern int usart1_tx (void *ptr, int len); -extern int usart2_tx (void *buf, size_t len); -extern void usart1_queue (uint8_t d); -extern void usart2_queue (uint8_t d); -extern void usart2_drain (void); -extern void usart1_drain (void); -extern void usart_init (void); +extern void usart1_isr(void); +extern void usart2_isr(void); +extern int _write(int file, char *ptr, int len); +extern int usart1_tx(void *ptr, int len); +extern int usart2_tx(void *buf, size_t len); +extern void usart1_queue(uint8_t d); +extern void usart2_queue(uint8_t d); +extern void usart2_drain(void); +extern void usart1_drain(void); +extern void usart_init(void); /* ring.c */ -extern void ring_init (ring_t * r, uint8_t * buf, size_t len); -extern int ring_write_byte (ring_t * r, uint8_t c); -extern int ring_read_byte (ring_t * r, uint8_t * c); -extern int ring_write (ring_t * r, uint8_t * buf, size_t len); -extern int ring_empty (ring_t * r); +extern void ring_init(ring_t *r, uint8_t *buf, size_t len); +extern int ring_write_byte(ring_t *r, uint8_t c); +extern int ring_read_byte(ring_t *r, uint8_t *c); +extern int ring_write(ring_t *r, uint8_t *buf, size_t len); +extern int ring_empty(ring_t *r); /* serial.c */ -extern void serial_poll (void); +extern void serial_poll(void); /* gpio.c */ extern int hook; -extern void exti9_5_isr (void); -extern void exti15_10_isr (void); -extern void toggle_fake_hook (void); -extern void gpio_tick (void); -extern void gpio_init (void); +extern void exti9_5_isr(void); +extern void exti15_10_isr(void); +extern void toggle_fake_hook(void); +extern void gpio_tick(void); +extern void gpio_init(void); /* console.c */ -extern int console_tx (void *buf, size_t len); -/* buzzer.c */ +extern int console_tx(void *buf, size_t len); +/* ringer.c */ extern int ringing; -extern void buzzer_on (void); -extern void buzzer_off (void); -extern void buzzer_set_freq (int hz); -extern void buzzer_init (void); -extern void ring_tick (void); -extern void ring_off (void); -extern void ring (int l); +extern void ringer_tick(void); +extern void ringer_off(void); +extern void ringer_ring(int l); +extern void ringer_disable(void); +extern void ringer_enable(void); +extern void ringer_init(void); /* modem.c */ -extern void modem_send (char *buf); -extern void modem_line (void); -extern void modem_byte (uint8_t b); -extern void answer_call (void); -extern void terminate_call (void); -extern void modem_tick (void); -extern void modem_init (void); +extern int in_call; +extern int dialtone; +extern void modem_send(void); +extern void modem_cmd(char *buf); +extern void modem_dial(char *buf); +extern void modem_tone_off(void); +extern void modem_tone(int i); +extern void modem_tone_nu(void); +extern void modem_line(void); +extern void modem_byte(uint8_t b); +extern void answer_call(void); +extern void terminate_call(void); +extern void dialtone_on(void); +extern void dialtone_off(void); +extern void modem_tick(void); +extern void modem_init(void); /* dialstr.c */ -extern void dialstr_clear (void); -extern void dialstr_digit (int digit); -extern void dialstr_dial (void); -extern void dialstr_tick (void); +extern void dialstr_clear(void); +extern void dialstr_digit(char digit); +extern void dialstr_dial(void); +extern void dialstr_tick(void); diff --git a/app/buzzer.c b/app/ringer.c index d6f1eb2..edaad24 100644 --- a/app/buzzer.c +++ b/app/ringer.c @@ -2,13 +2,14 @@ static int period; static int place; +static int ringer_enabled=1; int ringing; #define C6 1047 #define E6 1319 -void +static void buzzer_on (void) { gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_2_MHZ, @@ -31,7 +32,7 @@ buzzer_on (void) timer_enable_counter (TIM1); } -void +static void buzzer_off (void) { gpio_set_mode (GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO8); @@ -41,7 +42,7 @@ buzzer_off (void) timer_disable_counter (TIM1); } -void +static void buzzer_set_freq (int hz) { period = (48000000 / 4) / hz; @@ -49,7 +50,7 @@ buzzer_set_freq (int hz) timer_set_period (TIM1, period); } -void +static void buzzer_init (void) { @@ -61,7 +62,7 @@ buzzer_init (void) void -ring_tick (void) +ringer_tick (void) { static int t; @@ -133,9 +134,8 @@ ring_tick (void) } - void -ring_off (void) +ringer_off (void) { place = 0; ringing = 0; @@ -143,8 +143,27 @@ ring_off (void) } void -ring (int l) +ringer_ring (int l) { //mb(); +if (!ringer_enabled) return; ringing = l; } + +void ringer_disable(void) +{ +ringer_enabled=0; +ringer_off(); +} + +void ringer_enable(void) +{ +ringer_enabled=1; +} + + + +void ringer_init(void) +{ +buzzer_init(); +} diff --git a/app/serial.c b/app/serial.c index 27307eb..cabe7f2 100644 --- a/app/serial.c +++ b/app/serial.c @@ -21,7 +21,9 @@ serial_poll (void) else if (v == '#') { toggle_fake_hook (); - modem_send ("ATDT120;"); + dialstr_digit(1); + dialstr_digit(2); + dialstr_digit(0); } else { diff --git a/app/ticker.c b/app/ticker.c index 6341353..e22fc8c 100644 --- a/app/ticker.c +++ b/app/ticker.c @@ -33,7 +33,7 @@ sys_tick_handler (void) #endif gpio_tick (); usb_tick (); - ring_tick (); + ringer_tick (); modem_tick (); dialstr_tick (); diff --git a/app/usart.c b/app/usart.c index f9ea210..0abb5ec 100644 --- a/app/usart.c +++ b/app/usart.c @@ -64,9 +64,11 @@ usart2_isr (void) data = usart_recv (USART2); ring_write_byte (&rx2_ring, data); +#if 0 usart1_queue (data); if (data == '\r') usart1_queue ('\n'); +#endif } @@ -83,9 +85,11 @@ usart2_isr (void) else { usart_send_blocking (USART2, data); +#if 0 usart1_queue (data); if (data == '\r') usart1_queue ('\n'); +#endif } } diff --git a/doc/BT_SIN_350v1p5.pdf b/doc/BT_SIN_350v1p5.pdf Binary files differnew file mode 100644 index 0000000..7c5aa34 --- /dev/null +++ b/doc/BT_SIN_350v1p5.pdf diff --git a/doc/BT_SIN_351v4p6.pdf b/doc/BT_SIN_351v4p6.pdf Binary files differnew file mode 100644 index 0000000..44fc67c --- /dev/null +++ b/doc/BT_SIN_351v4p6.pdf diff --git a/doc/TTP229.pdf b/doc/TTP229.pdf Binary files differdeleted file mode 100644 index ca4c896..0000000 --- a/doc/TTP229.pdf +++ /dev/null diff --git a/doc/TTP229B-Schematic-Diagram.pdf b/doc/TTP229B-Schematic-Diagram.pdf Binary files differdeleted file mode 100644 index 70d73f8..0000000 --- a/doc/TTP229B-Schematic-Diagram.pdf +++ /dev/null |