From 2565f4857ea9cdebdbba483e35a07d012aa3afce Mon Sep 17 00:00:00 2001 From: root Date: Sat, 20 Aug 2016 23:04:40 +0100 Subject: first working version --- app/Makefile | 2 +- app/dialstr.c | 49 ++++++++++++++++++++++++++ app/gpio.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++----- app/prototypes.h | 7 ++++ app/ticker.c | 1 + 5 files changed, 155 insertions(+), 9 deletions(-) create mode 100644 app/dialstr.c diff --git a/app/Makefile b/app/Makefile index 657109f..2a0672b 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 +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 diff --git a/app/dialstr.c b/app/dialstr.c new file mode 100644 index 0000000..f75a8e4 --- /dev/null +++ b/app/dialstr.c @@ -0,0 +1,49 @@ +#include "project.h" +#define DIGIT_TIMEOUT 4000 + +static char dialstr[32]="ATDT"; +static unsigned dialstr_ptr=4; +static int dialstr_timeout; + +void dialstr_clear(void) +{ +dialstr_ptr=4; +dialstr[dialstr_ptr]=';'; +dialstr[dialstr_ptr+1]=0; +} + + +void dialstr_digit(int digit) +{ +if (!dialstr_timeout) dialstr_clear(); +if (dialstr_ptr>=(sizeof(dialstr)-2)) return; + +dialstr[dialstr_ptr]='0'+digit; +dialstr_ptr++; +dialstr[dialstr_ptr]=';'; +dialstr[dialstr_ptr+1]=0; + +dialstr_timeout=DIGIT_TIMEOUT; +printf("Dialstr is now %s\r\n",dialstr+4); + +} + +void dialstr_dial(void) +{ +printf("Dialing %s\r\n",dialstr+4); +modem_send(dialstr); +} + +void dialstr_tick(void) +{ +if (!dialstr_timeout) return; +dialstr_timeout--; +if (dialstr_timeout) return; + +if (!hook) + dialstr_dial(); + +} + + + diff --git a/app/gpio.c b/app/gpio.c index 2eb41ce..e597d16 100644 --- a/app/gpio.c +++ b/app/gpio.c @@ -1,24 +1,64 @@ #include "project.h" +#define DEBOUNCE 10 +#define DIAL_BLACKOUT 90 /* (10pps)*/ + +static int hs_poll; +int hook; +static int dial_poll; +static int dial_pulse_blackout; +static int pulse_count; + -static int hs_poll=50,hook=-1; static int fake_hook; +static void exti5_isr(void) +{ +exti_reset_request(EXTI5); +dial_poll=DEBOUNCE; +} + +static void exti7_isr(void) +{ +exti_reset_request(EXTI7); +if (dial_pulse_blackout) return; +dial_pulse_blackout=DIAL_BLACKOUT; +pulse_count++; +} + + +static void exti14_isr(void) +{ +exti_reset_request(EXTI14); +hs_poll=DEBOUNCE; +} + + + +void exti9_5_isr(void) +{ +if (exti_get_flag_status(EXTI5)) exti5_isr(); +if (exti_get_flag_status(EXTI7)) exti7_isr(); +} void exti15_10_isr(void) { - exti_reset_request(EXTI14); -hs_poll=50; +if (exti_get_flag_status(EXTI14)) exti14_isr(); } + + static void hs_tick(void) { int h; + + if (!hs_poll) return; hs_poll--; + if (hs_poll) return; -h=!!gpio_get(GPIOC,GPIO14); +h=!gpio_get(GPIOC,GPIO14); h^=fake_hook; @@ -28,10 +68,11 @@ hook=h; printf("Hook is now %d\r\n",hook); -if ((!hook) && (ringing)) { +if (!hook) { + if (ringing) { ring_off(); answer_call(); - + } } if (hook) { @@ -39,22 +80,41 @@ if (hook) { terminate_call(); } - +} +static void dial_tick(void) { +int m; + +if (dial_pulse_blackout) dial_pulse_blackout--; +if (!dial_poll) return; +dial_poll--; +if (dial_poll) return; + +m=!!gpio_get(GPIOA,GPIO5); + + +if (m) return; +if (!pulse_count) return; + +dialstr_digit((pulse_count == 10) ? 0:pulse_count); +pulse_count=0; } + void toggle_fake_hook(void) { fake_hook^=1; -hs_poll=50; +hs_poll=DEBOUNCE; } void gpio_tick(void) { hs_tick(); +dial_tick(); + } @@ -69,6 +129,35 @@ void gpio_init(void) gpio_set(GPIOA,GPIO1); + /* Dial mute */ + gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO4); + gpio_set(GPIOA,GPIO4); + + gpio_set_mode (GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO5); + gpio_clear(GPIOA,GPIO5); + + + exti_select_source(EXTI5, GPIOA); + exti_set_trigger(EXTI5, EXTI_TRIGGER_BOTH); + exti_enable_request(EXTI5); + + /*Dial contacts */ + + gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO6); + gpio_set(GPIOA,GPIO6); + + gpio_set_mode (GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO7); + gpio_clear(GPIOA,GPIO7); + + + exti_select_source(EXTI7, GPIOA); + exti_set_trigger(EXTI7, EXTI_TRIGGER_RISING); + exti_enable_request(EXTI7); + + + nvic_enable_irq(NVIC_EXTI9_5_IRQ); + + /*hookswitch*/ gpio_set_mode (GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO15); gpio_set(GPIOC,GPIO15); diff --git a/app/prototypes.h b/app/prototypes.h index cf280b9..f9de05c 100644 --- a/app/prototypes.h +++ b/app/prototypes.h @@ -60,6 +60,8 @@ extern int ring_empty(ring_t *r); /* serial.c */ 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); @@ -83,3 +85,8 @@ extern void answer_call(void); extern void terminate_call(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); diff --git a/app/ticker.c b/app/ticker.c index 1870a15..05d5aeb 100644 --- a/app/ticker.c +++ b/app/ticker.c @@ -35,6 +35,7 @@ sys_tick_handler (void) usb_tick (); ring_tick(); modem_tick(); + dialstr_tick(); } -- cgit v1.2.3