summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/main.c158
1 files changed, 157 insertions, 1 deletions
diff --git a/main/main.c b/main/main.c
index d42f8ba..c44352c 100644
--- a/main/main.c
+++ b/main/main.c
@@ -1,6 +1,162 @@
#include <stdio.h>
+#include <unistd.h>
+#include "driver/gpio.h"
+
+struct Nixie
+{
+ uint8_t digit;
+ uint8_t D;
+ uint8_t C;
+ uint8_t B;
+ uint8_t A;
+};
+
+struct Nixie screen[4];
+
+#define N0_P0 CONFIG_N0_P0
+#define N0_P1 CONFIG_N0_P1
+#define N0_P2 CONFIG_N0_P2
+#define N0_P3 CONFIG_N0_P3
+#define N1_P0 CONFIG_N1_P0
+#define N1_P1 CONFIG_N1_P1
+#define N1_P2 CONFIG_N1_P2
+#define N1_P3 CONFIG_N1_P3
+#define N2_P0 CONFIG_N2_P0
+#define N2_P1 CONFIG_N2_P1
+#define N2_P2 CONFIG_N2_P2
+#define N2_P3 CONFIG_N2_P3
+#define N3_P0 CONFIG_N3_P0
+#define N3_P1 CONFIG_N3_P1
+#define N3_P2 CONFIG_N3_P2
+#define N3_P3 CONFIG_N3_P3
+#define GPIO_OUTPUT_PIN_SEL ((1ULL<<N0_P0) | (1ULL<<N0_P1) | (1ULL<<N0_P2) | (1ULL<<N0_P3) | (1ULL<<N1_P0) | (1ULL<<N1_P1) | (1ULL<<N1_P2) | (1ULL<<N1_P3) | (1ULL<<N2_P0) | (1ULL<<N2_P1) | (1ULL<<N2_P2) | (1ULL<<N2_P3) | (1ULL<<N3_P0) | (1ULL<<N3_P1) | (1ULL<<N3_P2) | (1ULL<<N3_P3))
+/*
+ * Let's say, GPIO_OUTPUT_IO_0=18, GPIO_OUTPUT_IO_1=19
+ * In binary representation,
+ * 1ULL<<GPIO_OUTPUT_IO_0 is equal to 0000000000000000000001000000000000000000 and
+ * 1ULL<<GPIO_OUTPUT_IO_1 is equal to 0000000000000000000010000000000000000000
+ * GPIO_OUTPUT_PIN_SEL 0000000000000000000011000000000000000000
+ * */
+
+void configure_screen(void)
+{
+ //zero-initialize the config structure.
+ gpio_config_t io_conf = {};
+ //disable interrupt
+ io_conf.intr_type = GPIO_INTR_DISABLE;
+ //set as output mode
+ io_conf.mode = GPIO_MODE_OUTPUT;
+ //bit mask of the pins that you want to set,e.g.GPIO18/19
+ io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
+ //disable pull-down mode
+ io_conf.pull_down_en = 0;
+ //disable pull-up mode
+ io_conf.pull_up_en = 0;
+ //configure GPIO with the given settings
+ gpio_config(&io_conf);
+
+ screen[0].digit = 0;
+ screen[0].C = N0_P0;
+ screen[0].B = N0_P1;
+ screen[0].D = N0_P2;
+ screen[0].A = N0_P3;
+ screen[1].digit = 0;
+ screen[1].C = N1_P0;
+ screen[1].B = N1_P1;
+ screen[1].D = N1_P2;
+ screen[1].A = N1_P3;
+ screen[2].digit = 0;
+ screen[2].C = N2_P0;
+ screen[2].B = N2_P1;
+ screen[2].D = N2_P2;
+ screen[2].A = N2_P3;
+ screen[3].digit = 0;
+ screen[3].C = N3_P0;
+ screen[3].B = N3_P1;
+ screen[3].D = N3_P2;
+ screen[3].A = N3_P3;
+ return;
+}
+
+void set_digit(struct Nixie* n)
+{
+ switch (n->digit) {
+ case 0:
+ gpio_set_level(n->D, 0);
+ gpio_set_level(n->C, 0);
+ gpio_set_level(n->B, 0);
+ gpio_set_level(n->A, 0);
+ break;
+ case 1:
+ gpio_set_level(n->D, 0);
+ gpio_set_level(n->C, 0);
+ gpio_set_level(n->B, 0);
+ gpio_set_level(n->A, 1);
+ break;
+ case 2:
+ gpio_set_level(n->D, 0);
+ gpio_set_level(n->C, 0);
+ gpio_set_level(n->B, 1);
+ gpio_set_level(n->A, 0);
+ break;
+ case 3:
+ gpio_set_level(n->D, 0);
+ gpio_set_level(n->C, 0);
+ gpio_set_level(n->B, 1);
+ gpio_set_level(n->A, 1);
+ break;
+ case 4:
+ gpio_set_level(n->D, 0);
+ gpio_set_level(n->C, 1);
+ gpio_set_level(n->B, 0);
+ gpio_set_level(n->A, 0);
+ break;
+ case 5:
+ gpio_set_level(n->D, 0);
+ gpio_set_level(n->C, 1);
+ gpio_set_level(n->B, 0);
+ gpio_set_level(n->A, 1);
+ break;
+ case 6:
+ gpio_set_level(n->D, 0);
+ gpio_set_level(n->C, 1);
+ gpio_set_level(n->B, 1);
+ gpio_set_level(n->A, 0);
+ break;
+ case 7:
+ gpio_set_level(n->D, 0);
+ gpio_set_level(n->C, 1);
+ gpio_set_level(n->B, 1);
+ gpio_set_level(n->A, 1);
+ break;
+ case 8:
+ gpio_set_level(n->D, 1);
+ gpio_set_level(n->C, 0);
+ gpio_set_level(n->B, 0);
+ gpio_set_level(n->A, 0);
+ break;
+ case 9:
+ gpio_set_level(n->D, 1);
+ gpio_set_level(n->C, 0);
+ gpio_set_level(n->B, 0);
+ gpio_set_level(n->A, 1);
+ break;
+ default:
+ break;
+ return;
+ }
+}
void app_main(void)
{
- printf("Hey!\n");
+ printf("N1_P3: %i\n", N1_P3);
+ configure_screen();
+ while(1){
+ for (uint8_t i = 0; i <= 9; ++i) {
+ printf("digit: %i\n", i);
+ screen[0].digit = i; // Update the digit
+ set_digit(&screen[0]); // Call set_digit function
+ sleep(1); // Sleep for 2 seconds
+ }
+ }
}