aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-03-02 16:31:55 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-03-02 16:31:55 +0100
commit92de1f03abff7b4f572144140730799ec635c461 (patch)
treeac09e87219d10c21a26703251fbdf505cf9a1b5b
parentd72ffd3a9ed108c1faf143894d609d1e26bc5084 (diff)
downloadglutte-o-matic-92de1f03abff7b4f572144140730799ec635c461.tar.gz
glutte-o-matic-92de1f03abff7b4f572144140730799ec635c461.tar.bz2
glutte-o-matic-92de1f03abff7b4f572144140730799ec635c461.zip
Allocate SQ2, DET 1750 and NF, partly adapt code, schematics and layout
-rw-r--r--doc/perfboard.svg100
-rw-r--r--doc/pio.txt8
-rw-r--r--doc/schematic.svg49
-rw-r--r--src/glutt-o-logique/analog_input.c2
-rw-r--r--src/glutt-o-logique/main.c36
-rw-r--r--src/glutt-o-logique/pio.c205
6 files changed, 278 insertions, 122 deletions
diff --git a/doc/perfboard.svg b/doc/perfboard.svg
index d08618e..f71184b 100644
--- a/doc/perfboard.svg
+++ b/doc/perfboard.svg
@@ -2312,11 +2312,11 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
- inkscape:zoom="4.1778968"
- inkscape:cx="938.65485"
- inkscape:cy="449.12091"
+ inkscape:zoom="1.6868812"
+ inkscape:cx="413.55815"
+ inkscape:cy="354.14576"
inkscape:document-units="px"
- inkscape:current-layer="layer4"
+ inkscape:current-layer="layer1"
showgrid="true"
inkscape:snap-object-midpoints="true"
inkscape:window-width="1876"
@@ -28421,7 +28421,7 @@
x="390.63733"
y="678.1145"
style="font-size:7.5px;line-height:1.25;font-family:sans-serif"
- id="tspan10923">SQ2</tspan></text>
+ id="tspan10923">FAX</tspan></text>
<g
id="g10955"
transform="rotate(90,446.4736,790.0999)">
@@ -29053,7 +29053,7 @@
x="456.88498"
y="638.22028"
style="font-size:7.5px;line-height:1.25;font-family:sans-serif"
- id="tspan11151">FAX</tspan></text>
+ id="tspan11151">SQ2</tspan></text>
<g
id="g11183"
transform="rotate(-90,297.58016,669.6681)">
@@ -29444,6 +29444,94 @@
id="path11297"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccc" />
+ <g
+ id="g11544"
+ transform="translate(297.63781,7.0866053)"
+ style="opacity:0.717">
+ <circle
+ style="opacity:1;fill:#007f00;fill-opacity:1;stroke:none;stroke-width:1.41732287;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ id="circle11538"
+ cx="170.07875"
+ cy="705.1181"
+ r="15" />
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:7.5px;line-height:23.4375px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;direction:ltr;text-anchor:start;opacity:1;fill:#faff5a;fill-opacity:1;stroke:none;stroke-width:1.41732287;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ x="158.20619"
+ y="707.84821"
+ id="text11542"><tspan
+ sodipodi:role="line"
+ id="tspan11540"
+ x="158.20619"
+ y="707.84821"
+ style="fill:#faff5a;fill-opacity:1;stroke-width:1.41732287">TODO</tspan></text>
+ </g>
+ <g
+ id="g11552"
+ transform="translate(382.67718,7.0866053)"
+ style="opacity:0.717">
+ <circle
+ style="opacity:1;fill:#007f00;fill-opacity:1;stroke:none;stroke-width:1.41732287;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ id="circle11546"
+ cx="170.07875"
+ cy="705.1181"
+ r="15" />
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:7.5px;line-height:23.4375px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;direction:ltr;text-anchor:start;opacity:1;fill:#faff5a;fill-opacity:1;stroke:none;stroke-width:1.41732287;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ x="158.20619"
+ y="707.84821"
+ id="text11550"><tspan
+ sodipodi:role="line"
+ id="tspan11548"
+ x="158.20619"
+ y="707.84821"
+ style="fill:#faff5a;fill-opacity:1;stroke-width:1.41732287">TODO</tspan></text>
+ </g>
+ <g
+ transform="translate(240.94489,191.33858)"
+ id="g11560"
+ style="opacity:0.717">
+ <circle
+ style="opacity:1;fill:#007f00;fill-opacity:1;stroke:none;stroke-width:1.41732287;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ id="circle11554"
+ cx="170.07875"
+ cy="705.1181"
+ r="15" />
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:7.5px;line-height:23.4375px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;direction:ltr;text-anchor:start;opacity:1;fill:#faff5a;fill-opacity:1;stroke:none;stroke-width:1.41732287;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ x="158.20619"
+ y="707.84821"
+ id="text11558"><tspan
+ sodipodi:role="line"
+ id="tspan11556"
+ x="158.20619"
+ y="707.84821"
+ style="fill:#faff5a;fill-opacity:1;stroke-width:1.41732287">TODO</tspan></text>
+ </g>
+ <g
+ id="g11536"
+ transform="translate(127.55906,-134.64568)"
+ style="opacity:0.717">
+ <circle
+ r="15"
+ cy="705.1181"
+ cx="170.07875"
+ id="path11527"
+ style="opacity:1;fill:#007f00;fill-opacity:1;stroke:none;stroke-width:1.41732287;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
+ <text
+ id="text11531"
+ y="707.84821"
+ x="158.20619"
+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:7.5px;line-height:23.4375px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;direction:ltr;text-anchor:start;opacity:1;fill:#faff5a;fill-opacity:1;stroke:none;stroke-width:1.41732287;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+ xml:space="preserve"><tspan
+ style="fill:#faff5a;fill-opacity:1;stroke-width:1.41732287"
+ y="707.84821"
+ x="158.20619"
+ id="tspan11529"
+ sodipodi:role="line">TODO</tspan></text>
+ </g>
</g>
<g
inkscape:groupmode="layer"
diff --git a/doc/pio.txt b/doc/pio.txt
index 3c45818..c8d74c0 100644
--- a/doc/pio.txt
+++ b/doc/pio.txt
@@ -1,6 +1,8 @@
Allocation of PIOs to functions
===============================
+Ref: Datasheet Table 7 on p. 45 and Table 9 on p. 60
+
Connexions Relais
-----------------
- in QRP_n PC1
@@ -15,14 +17,14 @@ Connexions Relais
- in REPLIE PC13
- out FAX PC14
- out GPS EPPS PC15
-- out SQ2 P??
-- out DET 1750 P??
+- out SQ2 PC0
+- out DET 1750 PA8
- i/o Dallas 1-wire PA1
Analog signals
--------------
-- in NF (demod audio) P??
+- in NF (demod audio) PB1 (ADC12 IN9)
- in Vcc 12V PA5 (ADC12 IN5)
- in SWR forward PA6 (ADC12 IN6)
- in SWR reflected PA7 (ADC12 IN7)
diff --git a/doc/schematic.svg b/doc/schematic.svg
index cab1bb8..a30c62c 100644
--- a/doc/schematic.svg
+++ b/doc/schematic.svg
@@ -154,9 +154,9 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
- inkscape:zoom="1.7582312"
- inkscape:cx="109.09857"
- inkscape:cy="408.01094"
+ inkscape:zoom="4.9730289"
+ inkscape:cx="607.84454"
+ inkscape:cy="255.58511"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
@@ -4453,7 +4453,7 @@
y="540.51709"
x="373.32974"
id="tspan5392"
- sodipodi:role="line">P???</tspan></text>
+ sodipodi:role="line">PB1</tspan></text>
</g>
<path
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.60000002;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
@@ -5737,36 +5737,36 @@
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"
- x="603.02747"
- y="865.39648"
+ x="605"
+ y="864.86218"
id="text5515-3"><tspan
sodipodi:role="line"
id="tspan5517-7"
- x="603.02747"
- y="865.39648"
- style="font-size:5.625px;line-height:1.25;font-family:sans-serif">ADC12 IN5</tspan></text>
+ x="605"
+ y="864.86218"
+ style="font-size:5.625px;line-height:1.25;font-family:sans-serif">ADC1 IN5</tspan></text>
<text
id="text5446"
- y="835.39648"
- x="603.02747"
+ y="834.86218"
+ x="605"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"
xml:space="preserve"><tspan
style="font-size:5.625px;line-height:1.25;font-family:sans-serif"
- y="835.39648"
- x="603.02747"
+ y="834.86218"
+ x="605"
id="tspan5448"
- sodipodi:role="line">ADC12 IN6</tspan></text>
+ sodipodi:role="line">ADC1 IN6</tspan></text>
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"
- x="603.02747"
- y="818.89648"
+ x="605"
+ y="819.86224"
id="text5450"><tspan
sodipodi:role="line"
id="tspan5452"
- x="603.02747"
- y="818.89648"
- style="font-size:5.625px;line-height:1.25;font-family:sans-serif">ADC12 IN7</tspan></text>
+ x="605"
+ y="819.86224"
+ style="font-size:5.625px;line-height:1.25;font-family:sans-serif">ADC1 IN7</tspan></text>
<g
id="g5434"
transform="matrix(0.28125,0,0,-0.28125,287.23425,1446.4321)">
@@ -8001,6 +8001,17 @@
d="m 735.00002,637.36221 22.5,10e-6 -10e-6,77.5 h 137.50001 v -10.5"
style="fill:none;stroke:#000000;stroke-width:0.60000002;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
sodipodi:nodetypes="ccccc" />
+ <text
+ xml:space="preserve"
+ style="font-style:normal;font-weight:normal;line-height:0%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"
+ x="605"
+ y="849.86218"
+ id="text11525"><tspan
+ sodipodi:role="line"
+ id="tspan11523"
+ x="605"
+ y="849.86218"
+ style="font-size:5.625px;line-height:1.25;font-family:sans-serif">ADC12 IN9</tspan></text>
</g>
<g
inkscape:groupmode="layer"
diff --git a/src/glutt-o-logique/analog_input.c b/src/glutt-o-logique/analog_input.c
index 33bb662..5f0e700 100644
--- a/src/glutt-o-logique/analog_input.c
+++ b/src/glutt-o-logique/analog_input.c
@@ -37,6 +37,8 @@
// Measured on the board itself
const float v_ref = 2.965f;
+#warning "TODO: initialise ADC2 and use it for NF input"
+
void analog_init(void)
{
// Enable ADC and GPIOA clocks
diff --git a/src/glutt-o-logique/main.c b/src/glutt-o-logique/main.c
index 4341d54..5ff89bf 100644
--- a/src/glutt-o-logique/main.c
+++ b/src/glutt-o-logique/main.c
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
- * Copyright (c) 2016 Matthias P. Braendli, Maximilien Cuony
+ * Copyright (c) 2019 Matthias P. Braendli, Maximilien Cuony
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -23,7 +23,6 @@
*/
#include "stm32f4xx_conf.h"
-#include "leds.h"
// This is a set of guards to make sure the FPU compile configuration
// is correct
@@ -47,39 +46,8 @@
# error "SOFTFP"
#endif
-void init(void);
-
-void init()
+void init(void)
{
- /* Initialise the onboard peripherals
- * Four LEDs and one push-button
- */
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
-
- // Configure PD12, PD13, PD14 and PD15 in output pushpull mode
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin =
- GPIOD_BOARD_LED_GREEN |
- GPIOD_BOARD_LED_ORANGE |
- GPIOD_BOARD_LED_RED |
- GPIOD_BOARD_LED_BLUE;
-
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
-
- // Init PushButton
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
-
-
/* Setup Watchdog
* The IWDG runs at 32kHz. With a prescaler of 32 -> 1kHz.
* Counting to 2000 / 1000 = 2 seconds
diff --git a/src/glutt-o-logique/pio.c b/src/glutt-o-logique/pio.c
index b7420dc..caf29bc 100644
--- a/src/glutt-o-logique/pio.c
+++ b/src/glutt-o-logique/pio.c
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
- * Copyright (c) 2016 Matthias P. Braendli
+ * Copyright (c) 2019 Matthias P. Braendli
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -24,43 +24,66 @@
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
+#include "stm32f4xx_conf.h"
/* See pio.txt for PIO allocation details */
-/* On GPIO C */
-#define GPIO_PIN_QRP_n GPIO_Pin_1
-#define GPIO_PIN_TX GPIO_Pin_2
-#define GPIO_PIN_1750_n GPIO_Pin_4
-#define GPIO_PIN_MOD_OFF GPIO_Pin_5
-#define GPIO_PIN_SQ_n GPIO_Pin_6
-#define GPIO_PIN_U GPIO_Pin_8
-#define GPIO_PIN_QRP_out GPIO_Pin_9
-#define GPIO_PIN_D GPIO_Pin_11
-#define GPIO_PIN_REPLIE GPIO_Pin_13
-#define GPIO_PIN_FAX GPIO_Pin_14
-#define GPIO_PIN_GPS_EPPS GPIO_Pin_15
+#define GPIOA_PIN_DET_1750 GPIO_Pin_8
+#define GPIOA_PIN_PUSHBTN GPIO_Pin_0
+
+#define GPIOC_PIN_SQ2 GPIO_Pin_0
+#define GPIOC_PIN_QRP_n GPIO_Pin_1
+#define GPIOC_PIN_TX GPIO_Pin_2
+#define GPIOC_PIN_1750_n GPIO_Pin_4
+#define GPIOC_PIN_MOD_OFF GPIO_Pin_5
+#define GPIOC_PIN_SQ_n GPIO_Pin_6
+#define GPIOC_PIN_U GPIO_Pin_8
+#define GPIOC_PIN_QRP_out GPIO_Pin_9
+#define GPIOC_PIN_D GPIO_Pin_11
+#define GPIOC_PIN_REPLIE GPIO_Pin_13
+#define GPIOC_PIN_FAX GPIO_Pin_14
+#define GPIOC_PIN_GPS_EPPS GPIO_Pin_15
+
+
+#define GPIOA_INPUT_PINS ( \
+ GPIOA_PIN_PUSHBTN | \
+ 0)
+#define GPIOA_OUTPUT_PINS ( \
+ GPIOA_PIN_DET_1750 | \
+ 0)
#define GPIOC_OUTPUT_PINS ( \
- GPIO_PIN_TX | \
- GPIO_PIN_MOD_OFF | \
- GPIO_PIN_QRP_out | \
- GPIO_PIN_GPS_EPPS | \
+ GPIOC_PIN_TX | \
+ GPIOC_PIN_MOD_OFF | \
+ GPIOC_PIN_QRP_out | \
+ GPIOC_PIN_GPS_EPPS | \
+ GPIOC_PIN_FAX | \
+ GPIOC_PIN_SQ2 | \
0)
#undef GPIOC_OPENDRAIN_PINS
#undef GPIOC_INPUT_PU_PINS
#define GPIOC_INPUT_PINS ( \
- GPIO_PIN_QRP_n | \
- GPIO_PIN_1750_n | \
- GPIO_PIN_SQ_n | \
- GPIO_PIN_U | \
- GPIO_PIN_D | \
- GPIO_PIN_REPLIE | \
- GPIO_PIN_FAX | \
+ GPIOC_PIN_QRP_n | \
+ GPIOC_PIN_1750_n | \
+ GPIOC_PIN_SQ_n | \
+ GPIOC_PIN_U | \
+ GPIOC_PIN_D | \
+ GPIOC_PIN_REPLIE | \
+ GPIOC_PIN_FAX | \
0 )
+#define GPIOD_OUTPUT_PINS ( \
+ GPIOD_BOARD_LED_GREEN | \
+ GPIOD_BOARD_LED_ORANGE | \
+ GPIOD_BOARD_LED_RED | \
+ GPIOD_BOARD_LED_BLUE | \
+ 0 )
+
+#include "leds.h"
+
#include "GPIO/pio.h"
#include "Core/common.h"
#include "FreeRTOS.h"
@@ -72,19 +95,49 @@ void read_fsm_input_task(void *pvParameters);
struct fsm_input_signals_t pio_signals;
+static inline int all_equal(const uint8_t* v, uint8_t len)
+{
+ if (len < 2) {
+ return 1;
+ }
+
+ for (uint8_t i = 1; i < len; i++) {
+ if (v[i] != v[0])
+ return 0;
+ }
+ return 1;
+}
+
+static inline int any_true(const uint8_t* v, uint8_t len)
+{
+ if (len < 2) {
+ return 1;
+ }
+
+ for (uint8_t i = 0; i < len; i++) {
+ if (v[i])
+ return 1;
+ }
+ return 0;
+}
/* Some signals need additional debouncing or delays, the following
* variables are shift registers.
*/
-static uint8_t debounce_sq[3] = {0};
+#define DEBOUNCE_LEN_SQ 3
+static uint8_t debounce_sq[DEBOUNCE_LEN_SQ] = {0};
/* D and U have to stay on longer than SQ, otherwise the
* letter selection can fail, and transmit a K when it should
* send a D or U
*/
-static uint8_t debounce_discrim_d[6] = {0};
-static uint8_t debounce_discrim_u[6] = {0};
+#define DEBOUNCE_LEN_D_U 6
+static uint8_t debounce_discrim_d[DEBOUNCE_LEN_D_U] = {0};
+static uint8_t debounce_discrim_u[DEBOUNCE_LEN_D_U] = {0};
+/* This comes from the front panel button */
+#define DEBOUNCE_LEN_1750 3
+static uint8_t debounce_1750[DEBOUNCE_LEN_1750] = {0};
void pio_init()
{
@@ -92,8 +145,27 @@ void pio_init()
// Init pio
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
+ // For the onboard peripherals, 4x LEDs, 1 push-button:
+ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
+ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
+
+ // GPIO A
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
+ GPIO_InitStructure.GPIO_Pin = GPIOA_INPUT_PINS;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_Pin = GPIOA_OUTPUT_PINS;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_Init(GPIOA, &GPIO_InitStructure);
+
+ // GPIOC
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Pin = GPIOC_OUTPUT_PINS;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
@@ -118,14 +190,20 @@ void pio_init()
GPIO_Init(GPIOC, &GPIO_InitStructure);
#endif
-#if defined(GPIOC_INPUT_PINS)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Pin = GPIOC_INPUT_PINS;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
-#endif
+
+ // GPIO D
+ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
+ GPIO_InitStructure.GPIO_Pin = GPIOD_OUTPUT_PINS;
+ GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
+ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
+ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
+ GPIO_Init(GPIOD, &GPIO_InitStructure);
xTaskCreate(
read_fsm_input_task,
@@ -145,50 +223,55 @@ void read_fsm_input_task(void __attribute__ ((unused))*pvParameters)
{
while (1) {
pio_signals.qrp =
- GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_QRP_n) ? 0 : 1;
+ GPIO_ReadInputDataBit(GPIOC, GPIOC_PIN_QRP_n) ? 0 : 1;
- pio_signals.tone_1750 =
- GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_1750_n) ? 0 : 1;
+ for (int i = 0; i < DEBOUNCE_LEN_SQ-1; i++) {
+ debounce_sq[i] = debounce_sq[i+1];
+ }
- debounce_sq[0] = debounce_sq[1];
- debounce_sq[1] = debounce_sq[2];
- debounce_sq[2] =
- GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_SQ_n) ? 0 : 1;
+ debounce_sq[DEBOUNCE_LEN_SQ-1] =
+ GPIO_ReadInputDataBit(GPIOC, GPIOC_PIN_SQ_n) ? 0 : 1;
/* Only change the signal if its input has stabilised */
- if (debounce_sq[0] == debounce_sq[1] &&
- debounce_sq[1] == debounce_sq[2]) {
+ if (all_equal(debounce_sq, DEBOUNCE_LEN_SQ)) {
pio_signals.sq = debounce_sq[0];
}
/* The discrim U and D signals should be very sensitive:
* if one toggles to 1, set to 1; reset to 0 only if all
- * are at 0
+ * are at 0.
*/
- for (int i = 0; i < 5; i++) {
+ for (int i = 0; i < DEBOUNCE_LEN_D_U-1; i++) {
debounce_discrim_d[i] = debounce_discrim_d[i+1];
debounce_discrim_u[i] = debounce_discrim_u[i+1];
}
- debounce_discrim_u[5] =
- GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_U) ? 1 : 0;
+ debounce_discrim_u[DEBOUNCE_LEN_D_U-1] =
+ GPIO_ReadInputDataBit(GPIOC, GPIOC_PIN_U) ? 1 : 0;
+ pio_signals.discrim_u = any_true(debounce_discrim_u, DEBOUNCE_LEN_D_U);
+
+ debounce_discrim_d[DEBOUNCE_LEN_D_U-1] =
+ GPIO_ReadInputDataBit(GPIOC, GPIOC_PIN_D) ? 1 : 0;
+ pio_signals.discrim_d = any_true(debounce_discrim_d, DEBOUNCE_LEN_D_U);
- pio_signals.discrim_u =
- debounce_discrim_u[0] | debounce_discrim_u[1] | debounce_discrim_u[2] |
- debounce_discrim_u[3] | debounce_discrim_u[4] | debounce_discrim_u[5];
- debounce_discrim_d[5] =
- GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_D) ? 1 : 0;
+ for (int i = 0; i < DEBOUNCE_LEN_1750-1; i++) {
+ debounce_1750[i] = debounce_1750[i+1];
+ }
+
+ debounce_1750[DEBOUNCE_LEN_1750-1] =
+ GPIO_ReadInputDataBit(GPIOC, GPIOC_PIN_1750_n) ? 0 : 1;
- pio_signals.discrim_d =
- debounce_discrim_d[0] | debounce_discrim_d[1] | debounce_discrim_d[2] |
- debounce_discrim_d[3] | debounce_discrim_d[4] | debounce_discrim_d[5];
+ if (all_equal(debounce_1750, DEBOUNCE_LEN_1750)) {
+ pio_signals.tone_1750 = debounce_1750[0];
+ }
pio_signals.wind_generator_ok =
- GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_REPLIE) ? 0 : 1;
+ GPIO_ReadInputDataBit(GPIOC, GPIOC_PIN_REPLIE) ? 0 : 1;
+#warning "TODO: remove sstv_mode"
pio_signals.sstv_mode =
- GPIO_ReadInputDataBit(GPIOC, GPIO_PIN_FAX) ? 1 : 0;
+ GPIO_ReadInputDataBit(GPIOC, GPIOC_PIN_FAX) ? 1 : 0;
vTaskDelay(pdMS_TO_TICKS(100));
}
@@ -197,30 +280,30 @@ void read_fsm_input_task(void __attribute__ ((unused))*pvParameters)
void pio_set_tx(int on)
{
if (on) {
- GPIO_SetBits(GPIOC, GPIO_PIN_TX);
+ GPIO_SetBits(GPIOC, GPIOC_PIN_TX);
}
else {
- GPIO_ResetBits(GPIOC, GPIO_PIN_TX);
+ GPIO_ResetBits(GPIOC, GPIOC_PIN_TX);
}
}
void pio_set_qrp(int on)
{
if (on) {
- GPIO_SetBits(GPIOC, GPIO_PIN_QRP_out);
+ GPIO_SetBits(GPIOC, GPIOC_PIN_QRP_out);
}
else {
- GPIO_ResetBits(GPIOC, GPIO_PIN_QRP_out);
+ GPIO_ResetBits(GPIOC, GPIOC_PIN_QRP_out);
}
}
void pio_set_mod_off(int mod_off)
{
if (mod_off) {
- GPIO_SetBits(GPIOC, GPIO_PIN_MOD_OFF);
+ GPIO_SetBits(GPIOC, GPIOC_PIN_MOD_OFF);
}
else {
- GPIO_ResetBits(GPIOC, GPIO_PIN_MOD_OFF);
+ GPIO_ResetBits(GPIOC, GPIOC_PIN_MOD_OFF);
}
}
@@ -231,10 +314,12 @@ int pio_read_button() {
void pio_set_gps_epps(int on)
{
if (on) {
- GPIO_SetBits(GPIOC, GPIO_PIN_GPS_EPPS);
+ GPIO_SetBits(GPIOC, GPIOC_PIN_GPS_EPPS);
}
else {
- GPIO_ResetBits(GPIOC, GPIO_PIN_GPS_EPPS);
+ GPIO_ResetBits(GPIOC, GPIOC_PIN_GPS_EPPS);
}
}
+#warning "TODO: add output functions for SQ2, DET 1750 and FAX"
+