summaryrefslogtreecommitdiffstats
path: root/app/gpio.c
diff options
context:
space:
mode:
authorroot <root@lamia.panaceas.james.local>2016-08-20 20:55:43 +0100
committerroot <root@lamia.panaceas.james.local>2016-08-20 20:55:43 +0100
commite696ed2427fe036a0dcfe50f209e22a9f273d100 (patch)
tree837ac9421102a7b83a4d55b72e22fce5f6033214 /app/gpio.c
parentb063a2da3024a2e3175e1ba9b0a87cb6c7470765 (diff)
downloadcandlestick-e696ed2427fe036a0dcfe50f209e22a9f273d100.tar.gz
candlestick-e696ed2427fe036a0dcfe50f209e22a9f273d100.tar.bz2
candlestick-e696ed2427fe036a0dcfe50f209e22a9f273d100.zip
working calls
Diffstat (limited to 'app/gpio.c')
-rw-r--r--app/gpio.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/app/gpio.c b/app/gpio.c
new file mode 100644
index 0000000..2eb41ce
--- /dev/null
+++ b/app/gpio.c
@@ -0,0 +1,86 @@
+#include "project.h"
+
+static int hs_poll=50,hook=-1;
+
+static int fake_hook;
+
+void exti15_10_isr(void)
+{
+ exti_reset_request(EXTI14);
+hs_poll=50;
+}
+
+static void hs_tick(void)
+{
+int h;
+if (!hs_poll) return;
+hs_poll--;
+
+if (hs_poll) return;
+
+h=!!gpio_get(GPIOC,GPIO14);
+
+h^=fake_hook;
+
+if (hook==h) return;
+
+hook=h;
+
+printf("Hook is now %d\r\n",hook);
+
+if ((!hook) && (ringing)) {
+ ring_off();
+ answer_call();
+
+}
+
+if (hook) {
+ ring_off();
+ terminate_call();
+}
+
+
+
+
+
+}
+
+
+void toggle_fake_hook(void)
+{
+fake_hook^=1;
+hs_poll=50;
+}
+
+void gpio_tick(void)
+{
+hs_tick();
+}
+
+
+
+
+
+void gpio_init(void)
+{
+ /*GSM module reset pin*/
+ gpio_set_mode (GPIOA, GPIO_MODE_OUTPUT_2_MHZ,
+ GPIO_CNF_OUTPUT_PUSHPULL, GPIO1);
+ gpio_set(GPIOA,GPIO1);
+
+
+ /*hookswitch*/
+ gpio_set_mode (GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO15);
+ gpio_set(GPIOC,GPIO15);
+
+ gpio_set_mode (GPIOC, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, GPIO14);
+ gpio_clear(GPIOC,GPIO14);
+
+
+ exti_select_source(EXTI14, GPIOC);
+ exti_set_trigger(EXTI14, EXTI_TRIGGER_BOTH);
+ exti_enable_request(EXTI14);
+
+ nvic_enable_irq(NVIC_EXTI15_10_IRQ);
+
+}