Skip to content

Commit 4b41fb2

Browse files
committed
crsf and ssd1306 added
1 parent 6b72148 commit 4b41fb2

File tree

9 files changed

+377
-22
lines changed

9 files changed

+377
-22
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"string": "c",
1010
"string_view": "c",
1111
"ble_svc_gap.h": "c",
12-
"console.h": "c"
12+
"console.h": "c",
13+
"esp_nimble_hci.h": "c"
1314
}
1415
}

components/crsf/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(srcs "crsf.c")
2+
3+
idf_component_register(SRCS "${srcs}"
4+
INCLUDE_DIRS "include")

main/crsf.c renamed to components/crsf/crsf.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
#include <stdio.h>
2-
#include "freertos/FreeRTOS.h"
3-
#include "freertos/task.h"
4-
#include "driver/uart.h"
5-
#include "driver/gpio.h"
6-
#include "esp_log.h"
7-
#include "hal/uart_hal.h"
1+
#include "crsf.h"
82

93
uint8_t crcSingleChar(uint8_t crc, uint8_t a)
104
{
@@ -26,8 +20,7 @@ uint8_t crcMessage(uint8_t message[], uint8_t length)
2620
return crc;
2721
}
2822

29-
static void echo_task(void *arg)
30-
{
23+
void initCRSF_read(){
3124
/* Configure parameters of an UART driver,
3225
* communication pins and install the driver */
3326
//uart driver erstellt eigene interrupts
@@ -55,13 +48,13 @@ static void echo_task(void *arg)
5548
//diese interrupt schwellwellen speichern
5649
ESP_ERROR_CHECK(uart_intr_config(UART_NUM_2, &uart_intr));
5750
ESP_ERROR_CHECK(uart_enable_rx_intr(UART_NUM_2));
51+
}
5852

53+
void crsf_get_ChannelData_task(void *arg)
54+
{
5955
// Configure a temporary buffer for the incoming data
6056
uint8_t *data = (uint8_t *) malloc(1024);
6157

62-
//store channel data in array
63-
uint16_t channelData[16] = {0};
64-
6558
while (1) {
6659
// get size in uart buffer
6760
int length = 0;
@@ -73,7 +66,7 @@ static void echo_task(void *arg)
7366
//read uart data
7467
int len = uart_read_bytes(UART_NUM_2, data, length, 20 / portTICK_RATE_MS);
7568

76-
//RX Buffer leeren wenn Frame gelesen wurde
69+
//RX Buffer leeren wenn Frame im temporären buffer
7770
uart_flush(UART_NUM_2);
7871

7972
//len of data read from rx buffer
@@ -129,7 +122,8 @@ static void echo_task(void *arg)
129122
channelData[j] = value;
130123
}
131124
//Kanaldaten ausgeben
132-
ESP_LOGI("Channel-Data","%4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d", channelData[0], channelData[1], channelData[2], channelData[3], channelData[4], channelData[5], channelData[6], channelData[7], channelData[8], channelData[9], channelData[10], channelData[11], channelData[12], channelData[13], channelData[14], channelData[15]);
125+
//wenn esp_logi ausgegeben wird dann kann es sein das watchdog timer für den task nicht zurückgesetzt wird ist aber nicht so schlimm solang der output einfach weggelassen wird in stpäteren code
126+
//ESP_LOGI("Channel-Data","%4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d %4d", channelData[0], channelData[1], channelData[2], channelData[3], channelData[4], channelData[5], channelData[6], channelData[7], channelData[8], channelData[9], channelData[10], channelData[11], channelData[12], channelData[13], channelData[14], channelData[15]);
133127
break;
134128
}
135129
}
@@ -140,9 +134,4 @@ static void echo_task(void *arg)
140134
vTaskDelay(10 / portTICK_PERIOD_MS);
141135
}
142136
}
143-
}
144-
145-
void app_main(void)
146-
{
147-
xTaskCreate(echo_task, "uart_echo_task", 2048, NULL, 10, NULL);
148137
}

components/crsf/include/crsf.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef CRSF_H
2+
#define CRSF_H
3+
4+
#include "hal/uart_hal.h"
5+
#include "driver/uart.h"
6+
#include "freertos/task.h"
7+
#include "esp_log.h"
8+
9+
//store channel data in array
10+
static uint16_t channelData[16] = {0};
11+
12+
uint8_t crcSingleChar(uint8_t crc, uint8_t a);
13+
uint8_t crcMessage(uint8_t message[], uint8_t length);
14+
void initCRSF_read();
15+
void crsf_get_ChannelData_task(void *arg);
16+
17+
#endif

components/ssd1306/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(srcs "ssd1306.c")
2+
3+
idf_component_register(SRCS "${srcs}"
4+
INCLUDE_DIRS "include")
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#ifndef SSD1306_H
2+
#define SSD1306_H
3+
4+
//credits: https://github.com/nopnop2002/esp-idf-ssd1306
5+
// http://robotcantalk.blogspot.com/2015/03/interfacing-arduino-with-ssd1306-driven.html
6+
7+
#include "driver/i2c.h"
8+
#include "esp_log.h"
9+
#include <string.h>
10+
#include <stdbool.h>
11+
12+
//SLA (0x3C) + WRITE_MODE (0x00) = 0x78 (0b01111000)
13+
#define SSD1306_ADDRESS 0x3C
14+
15+
//allgemeine infos
16+
//startup des ssd1306 wird durch Kondensatoren auf dem PCB geregelt --> beachten bei pcb design
17+
#define SSD1306_WIDTH 128
18+
#define SSD1306_HEIGHT 32
19+
#define SSD1306_PAGES 8
20+
#define SSD1306_TAG "SSD1306"
21+
#define SSD1306_I2C_NUM_CON I2C_NUM_0
22+
23+
//setzen des controllbytes für die art der daten die folgend kommen
24+
#define SSD1306_CONTROL_BYTE_CMD_STREAM 0x00
25+
#define SSD1306_CONTROL_BYTE_CMD_SINGLE 0x80
26+
#define SSD1306_CONTROL_BYTE_DATA_SINGLE 0xC0
27+
#define SSD1306_CONTROL_BYTE_DATA_STREAM 0x40
28+
29+
//grundbefehle
30+
#define SSD1306_CMD_SET_CONTRAST 0x81 // gefolgt von 0x7F
31+
#define SSD1306_CMD_DISPLAY_RAM 0xA4
32+
#define SSD1306_CMD_DISPLAY_ALLON 0xA5
33+
#define SSD1306_CMD_DISPLAY_NORMAL 0xA6
34+
#define SSD1306_CMD_DISPLAY_INVERTED 0xA7
35+
#define SSD1306_CMD_DISPLAY_OFF 0xAE
36+
#define SSD1306_CMD_DISPLAY_ON 0xAF
37+
38+
//GDDRAM (Graphic Display Data RAM) adressierung
39+
#define SSD1306_CMD_SET_MEMORY_ADDR_MODE 0x20
40+
#define SSD1306_CMD_SET_HORI_ADDR_MODE 0x00 // horizontaler adressierungsmodus
41+
#define SSD1306_CMD_SET_VERT_ADDR_MODE 0x01 // vertikaler adressierungsmodus
42+
#define SSD1306_CMD_SET_PAGE_ADDR_MODE 0x02 // page adressierungsmodus
43+
#define SSD1306_CMD_SET_COLUMN_RANGE 0x21 // can be used only in HORZ/VERT mode - follow with 0x00 and 0x7F = COL127
44+
#define SSD1306_CMD_SET_PAGE_RANGE 0x22 // can be used only in HORZ/VERT mode - follow with 0x00 and 0x07 = PAGE7
45+
46+
//Hardwarekonfiguration
47+
#define SSD1306_CMD_SET_DISPLAY_START_LINE 0x40
48+
#define SSD1306_CMD_SET_SEGMENT_REMAP_0 0xA0
49+
#define SSD1306_CMD_SET_SEGMENT_REMAP_1 0xA1
50+
#define SSD1306_CMD_SET_MUX_RATIO 0xA8 // follow with 0x3F = 64 MUX
51+
#define SSD1306_CMD_SET_COM_SCAN_MODE_1 0xC8
52+
#define SSD1306_CMD_SET_COM_SCAN_MODE_0 0xC0
53+
#define SSD1306_CMD_SET_DISPLAY_OFFSET 0xD3 // follow with 0x00
54+
#define SSD1306_CMD_SET_COM_PIN_MAP 0xDA // follow with 0x12
55+
#define SSD1306_CMD_NOP 0xE3 // NOP
56+
57+
// Timing and Driving Scheme
58+
#define SSD1306_CMD_SET_DISPLAY_CLK_DIV 0xD5 // follow with 0x80
59+
#define SSD1306_CMD_SET_PRECHARGE 0xD9 // follow with 0xF1
60+
#define SSD1306_CMD_SET_VCOMH_DESELECT 0xDB // follow with 0x30
61+
62+
// Charge Pump
63+
#define SSD1306_CMD_SET_CHARGE_PUMP 0x8D // follow with 0x14
64+
65+
// Scrolling Befehle
66+
#define SSD1306_CMD_DEACTIVE_SCROLL 0x2E
67+
68+
//buffer damit der aktuelle Output auch im Speicher des ESP vorhanden ist
69+
uint8_t* ssd1306_buffer;
70+
71+
void ssd1306_init();
72+
void I2C_master_init();
73+
void ssd1306_clear();
74+
void ssd1306_display();
75+
void ssd1306_setPixel(uint8_t x, uint8_t y, bool status);
76+
void ssd1306_setChar(char c, uint8_t x, uint8_t y);
77+
void ssd1306_setString(const char* str, uint8_t x, uint8_t y);
78+
79+
#endif
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#ifndef SSD1306_FONT_H
2+
#define SSD1306_FONT_H
3+
4+
#define CHAR_WIDTH 10
5+
#define CHAR_HEIGHT 14
6+
7+
//Ein Hex wert stellt eine Spalte eines Zeichen dar
8+
//lsb sind die unteren pixel des zeichens
9+
//die 2 msb werden immer übersprungen
10+
const uint16_t VCR_OSD_MONO[43][10] = {
11+
{0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}, //
12+
{0x0038,0x00FE,0x19C7,0x1983,0x1983,0x1983,0x1983,0x1CC6,0x0FFF,0x07FF}, // a
13+
{0x3FFF,0x3FFF,0x01FC,0x038E,0x0707,0x0603,0x0707,0x038E,0x01FC,0x00F8}, // b
14+
{0x01FC,0x03FE,0x0707,0x0603,0x0603,0x0603,0x0603,0x0707,0x038E,0x018C}, // c
15+
{0x00F8,0x01FC,0x038E,0x0707,0x0603,0x0707,0x038E,0x01FC,0x3FFF,0x3FFF}, // d
16+
{0x01FC,0x03FE,0x0767,0x0663,0x0663,0x0663,0x0663,0x0767,0x03E6,0x01C4}, // e
17+
{0x0000,0x0300,0x0300,0x0300,0x1FFF,0x3FFF,0x3300,0x3300,0x3300,0x0000}, // f
18+
{0x0380,0x07C6,0x0EE7,0x0C63,0x0C63,0x0C63,0x0C63,0x0EC7,0x07FE,0x03FC}, // g
19+
{0x3FFF,0x3FFF,0x01C0,0x0380,0x0700,0x0600,0x0700,0x0380,0x01FF,0x00FF}, // h
20+
{0x0000,0x0000,0x0180,0x0180,0x19FC,0x19FE,0x0007,0x0003,0x0000,0x0000}, // i
21+
{0x0000,0x0000,0x0003,0x0003,0x0603,0x0607,0x37FE,0x37FC,0x0000,0x0000}, // j
22+
{0x3FFF,0x3FFF,0x001C,0x0038,0x0070,0x00F8,0x01DC,0x038E,0x0707,0x0603}, // k
23+
{0x0000,0x0000,0x0000,0x0000,0x3FFF,0x3FFF,0x0000,0x0000,0x0000,0x0000}, // l
24+
{0x07FF,0x07FF,0x0300,0x0600,0x07FF,0x07FF,0x0600,0x0700,0x03FF,0x01FF}, // m
25+
{0x07FF,0x07FF,0x0300,0x0600,0x0600,0x0600,0x0600,0x0700,0x03FF,0x01FF}, // n
26+
{0x01FC,0x03FE,0x0707,0x0603,0x0603,0x0603,0x0603,0x0707,0x03FE,0x01FC}, // o
27+
{0x0FFF,0x0FFF,0x07F0,0x0E38,0x0C18,0x0C18,0x0C18,0x0E38,0x07F0,0x03E0}, // p
28+
{0x03E0,0x07F0,0x0E38,0x0C18,0x0C18,0x0C18,0x0E38,0x07F0,0x0FFF,0x0FFF}, // q
29+
{0x07FF,0x07FF,0x01C0,0x0380,0x0700,0x0600,0x0600,0x0700,0x0380,0x0180}, // r
30+
{0x018C,0x03CE,0x07C7,0x0663,0x0663,0x0673,0x0633,0x073F,0x039E,0x018C}, // s
31+
{0x0000,0x0000,0x0600,0x0600,0x3FFC,0x3FFE,0x0607,0x0603,0x0000,0x0000}, // t
32+
{0x07FC,0x07FE,0x0007,0x0003,0x0003,0x0003,0x0003,0x0007,0x07FE,0x07FC}, // u
33+
{0x07F0,0x07F8,0x001C,0x000E,0x0007,0x0007,0x000E,0x001C,0x07F8,0x07F0}, // v
34+
{0x07FC,0x07FE,0x0007,0x0003,0x007E,0x007E,0x0003,0x0007,0x07FE,0x07FC}, // w
35+
{0x0603,0x0707,0x038E,0x01DC,0x00F8,0x00F8,0x01DC,0x038E,0x0707,0x0603}, // x
36+
{0x0FC0,0x0FE0,0x0073,0x0033,0x0033,0x0073,0x00E3,0x03C7,0x0FFE,0x0FFC}, // y
37+
{0x0603,0x0607,0x060F,0x061F,0x063B,0x0673,0x06E3,0x07C3,0x0783,0x0703}, // z
38+
{0x0FFC,0x1FFE,0x3837,0x3073,0x30E3,0x31C3,0x3383,0x3B07,0x1FFE,0x0FFC}, // 0
39+
{0x0000,0x0000,0x0C03,0x1C03,0x3FFF,0x3FFF,0x0003,0x0003,0x0000,0x0000}, // 1
40+
{0x0C3F,0x1C7F,0x38E3,0x30C3,0x30C3,0x30C3,0x30C3,0x39C3,0x1F83,0x0F03}, // 2
41+
{0x0C0C,0x1C0E,0x3807,0x3003,0x30C3,0x30C3,0x30C3,0x39E7,0x1FFE,0x0F3C}, // 3
42+
{0x00F0,0x01F0,0x03B0,0x0730,0x0E30,0x1C30,0x3FFF,0x3FFF,0x0030,0x0030}, // 4
43+
{0x3F0C,0x3F0E,0x3307,0x3303,0x3303,0x3303,0x3303,0x3387,0x31FE,0x30FC}, // 5
44+
{0x0FFC,0x1FFE,0x38C7,0x30C3,0x30C3,0x30C3,0x30C3,0x38E7,0x1C7E,0x0C3C}, // 6
45+
{0x3000,0x3000,0x3000,0x3000,0x307F,0x30FF,0x31C0,0x3380,0x3F00,0x3E00}, // 7
46+
{0x0F3C,0x1FFE,0x39E7,0x30C3,0x30C3,0x30C3,0x30C3,0x39E7,0x1FFE,0x0F3C}, // 8
47+
{0x0F0C,0x1F8E,0x39C7,0x30C3,0x30C3,0x30C3,0x30C3,0x38C7,0x1FFE,0x0FFC}, // 9
48+
{0x1E0F,0x3F1F,0x3338,0x3F70,0x1EE0,0x01DE,0x03BF,0x0733,0x3E3F,0x3C1E}, // %
49+
{0x0C00,0x1C00,0x3800,0x3000,0x3033,0x3073,0x30E0,0x39C0,0x1F80,0x0F00}, // ?
50+
{0x0000,0x0000,0x0000,0x0000,0x07F3,0x07F3,0x0000,0x0000,0x0000,0x0000}, // !
51+
{0x0000,0x0000,0x0000,0x0000,0x0003,0x0003,0x0000,0x0000,0x0000,0x0000}, // .
52+
{0x0000,0x00C0,0x00C0,0x00C0,0x00C0,0x00C0,0x00C0,0x00C0,0x00C0,0x0000}, // -
53+
{0x0000,0x3FFF,0x3FFF,0x3003,0x3003,0x3003,0x3003,0x3FFF,0x3FFF,0x0000}, // unknown
54+
};
55+
56+
#endif

0 commit comments

Comments
 (0)