Implementation OLED
This commit is contained in:
parent
6c1df1f371
commit
2fb97ec4f7
@ -1,12 +1,21 @@
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(synch)
|
||||
project(EdSaGfmvA)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE
|
||||
src/main.c
|
||||
src/epaper/epaper.c
|
||||
src/lora/encryption.c
|
||||
src/lora/synch.c
|
||||
src/oled/oled.c
|
||||
src/utils/constAndVars.c
|
||||
src/utils/buttons.c
|
||||
src/utils/leds.c
|
||||
)
|
||||
|
||||
set(DTC_EXTRA_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/dts/bindings")
|
||||
|
||||
target_include_directories(app PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
)
|
13
README.rst
13
README.rst
@ -1,3 +1,5 @@
|
||||
EPaper
|
||||
|
||||
Ports: Anschluss Port
|
||||
VCC (grau) CN6:4 3V3
|
||||
GND (braun) CN6:6 GND
|
||||
@ -8,6 +10,17 @@ DC (grün) CN9:6 GPIO B8
|
||||
RST (weiß) CN9:8 GPIO C1
|
||||
BUSY (lila) CN9:7 GPIO B10
|
||||
|
||||
OLED
|
||||
Ports: Anschluss Port
|
||||
VCC VSS (grau) CN6:4 3V3
|
||||
GND VDD (braun) CN6:6 GND
|
||||
DIN D0 (blau) CN5:4 GPIO A7
|
||||
CLK D1 (gelb) CN5:6 GPIO A5
|
||||
CS CS (orange) CN5:3 GPIO A4
|
||||
DC A0 (grün) CN9:6 GPIO B8
|
||||
RST RST (weiß) CN9:8 GPIO C1
|
||||
|
||||
|
||||
Bei start:
|
||||
source zephyrproject/.venv/bin/activate
|
||||
cd zephyrproject/EdSaGfmvA/
|
||||
|
@ -16,4 +16,22 @@
|
||||
busy-gpios = <&gpiob 10 GPIO_ACTIVE_HIGH>;
|
||||
cs-gpios = <&gpioa 4 GPIO_ACTIVE_HIGH>;
|
||||
};
|
||||
|
||||
oled: oled@1 {
|
||||
compatible = "marvin,oled128x64"; // <-- ✅ Erlaubt CS/DC/RESET Nutzung
|
||||
reg = <1>;
|
||||
spi-max-frequency = <2000000>;
|
||||
|
||||
dc-gpios = <&gpiob 8 GPIO_ACTIVE_HIGH>;
|
||||
reset-gpios = <&gpioc 1 GPIO_ACTIVE_HIGH>;
|
||||
cs-gpios = <&gpioa 4 GPIO_ACTIVE_HIGH>;
|
||||
|
||||
label = "OLED";
|
||||
};
|
||||
};
|
||||
|
||||
/ {
|
||||
aliases {
|
||||
oled = &oled;
|
||||
};
|
||||
};
|
16
dts/bindings/display/oled128x64.yaml
Normal file
16
dts/bindings/display/oled128x64.yaml
Normal file
@ -0,0 +1,16 @@
|
||||
description: Custom OLED 128x64
|
||||
|
||||
compatible: "marvin,oled128x64"
|
||||
|
||||
include: spi-device.yaml
|
||||
|
||||
properties:
|
||||
dc-gpios:
|
||||
type: phandle-array
|
||||
required: true
|
||||
reset-gpios:
|
||||
type: phandle-array
|
||||
required: true
|
||||
cs-gpios:
|
||||
type: phandle-array
|
||||
required: true
|
@ -6,10 +6,10 @@
|
||||
#include <zephyr/drivers/spi.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
|
||||
#define WIDTH 200
|
||||
#define WIDTH 250
|
||||
#define HEIGHT 122
|
||||
#define BYTES_PER_LINE 25 // ((WIDTH + 7) / 8)
|
||||
#define ALLSCREEN_GRAGHBYTES 3050 //(BYTES_PER_LINE * HEIGHT)
|
||||
#define BYTES_PER_LINE 32 // ((WIDTH + 7) / 8)
|
||||
#define ALLSCREEN_GRAGHBYTES 3904 //(BYTES_PER_LINE * HEIGHT)
|
||||
|
||||
void epd_init(void);
|
||||
void epd_update(void);
|
||||
@ -17,6 +17,6 @@ void epd_clear_black(void);
|
||||
void epd_clear_white(void);
|
||||
void epd_display_buffer(const unsigned char *buffer);
|
||||
|
||||
void draw_something(int num);
|
||||
void draw_something(char toDraw);
|
||||
|
||||
#endif // EPAPER_H
|
||||
#endif
|
@ -1,3 +1,5 @@
|
||||
#ifndef LORA_H
|
||||
#define LORA_H
|
||||
|
||||
#define DEFAULT_RADIO_NODE DT_ALIAS(lora0)
|
||||
|
||||
@ -11,4 +13,6 @@ struct lora_modem_config config = {
|
||||
.coding_rate = CR_4_5,
|
||||
.tx_power = 14,
|
||||
.tx = false,
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
@ -1,19 +0,0 @@
|
||||
#include <zephyr/kernel.h>
|
||||
|
||||
#define MAX_SAMPLES 10
|
||||
|
||||
// Vorwärtsdeklarationen
|
||||
void synchronite(struct k_work *work);
|
||||
K_WORK_DEFINE(sync_work, synchronite);
|
||||
|
||||
// Hardware
|
||||
static struct gpio_callback button_cb_data;
|
||||
|
||||
// Sync-Variablen
|
||||
uint32_t offsets[MAX_SAMPLES];
|
||||
uint8_t offset_count = 0;
|
||||
uint32_t sync_offset = 0;
|
||||
uint32_t sync_offset_s = 0;
|
||||
bool synchronized = false;
|
||||
|
||||
uint32_t samples[MAX_SAMPLES];
|
16
include/lora/synch.h
Normal file
16
include/lora/synch.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef SYNCH_H
|
||||
#define SYNCH_H
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include "utils/leds.h"
|
||||
#include "utils/constAndVars.h"
|
||||
|
||||
#define MAX_SAMPLES 10
|
||||
|
||||
// Vorwärtsdeklarationen
|
||||
void synchronite(struct k_work *work);
|
||||
|
||||
// Hardware
|
||||
//extern struct gpio_callback button_cb_data;
|
||||
|
||||
#endif
|
14
include/oled/oled.h
Normal file
14
include/oled/oled.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef OLED_H
|
||||
#define OLED_H
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/spi.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
|
||||
#define WIDTH 128
|
||||
#define HEIGHT 64
|
||||
#define BYTES_PER_LINE 16 // ((WIDTH + 7) / 8)
|
||||
#define ALLSCREEN_GRAGHBYTES 1024 //(BYTES_PER_LINE * HEIGHT)
|
||||
|
||||
#endif
|
@ -1,3 +1,11 @@
|
||||
#ifndef BUTTONS_H
|
||||
#define BUTTONS_H
|
||||
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/devicetree.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
|
||||
#define SW0_NODE DT_ALIAS(sw0)
|
||||
static const struct gpio_dt_spec button0 = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios, {0});
|
||||
extern const struct gpio_dt_spec button0;
|
||||
|
||||
#endif
|
@ -1,6 +1,13 @@
|
||||
#ifndef CONSTANDVARS_H
|
||||
#define CONSTANDVARS_H
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
boolean slave = false;
|
||||
boolean error = false;
|
||||
extern bool slave;
|
||||
extern bool error;
|
||||
extern bool synchronized;
|
||||
extern uint32_t nextSynchro;
|
||||
|
||||
uint32_t nextSynchro = -1
|
||||
#endif // CONSTANDVARS_H
|
||||
|
@ -1,9 +1,20 @@
|
||||
#ifndef LEDS_H
|
||||
#define LEDS_H
|
||||
|
||||
#include <zephyr/devicetree.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
|
||||
#include "lora/synch.h"
|
||||
#include "utils/constAndVars.h"
|
||||
|
||||
#define LED0_NODE DT_ALIAS(led0)
|
||||
static const struct gpio_dt_spec led_green = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
|
||||
|
||||
extern const struct gpio_dt_spec led_green;
|
||||
|
||||
//#define LED1_NODE DT_ALIAS(led1)
|
||||
//static const struct gpio_dt_spec led_blue = GPIO_DT_SPEC_GET(LED1_NODE, gpios);
|
||||
|
||||
void updateLEDs(void);
|
||||
void turnOutLEDS(void);
|
||||
void updateLEDs(void);
|
||||
|
||||
#endif
|
5
prj.conf
5
prj.conf
@ -6,9 +6,4 @@ CONFIG_GPIO=y
|
||||
CONFIG_LORA=y
|
||||
CONFIG_LORA_SHELL=y
|
||||
|
||||
#CONFIG_SPI_LOG_LEVEL_DBG=y
|
||||
#CONFIG_LOG=y
|
||||
#CONFIG_LOG_MODE_DEFERRED=n
|
||||
#CONFIG_LOG_BACKEND_UART=y
|
||||
|
||||
CONFIG_MAIN_STACK_SIZE=2048
|
@ -2,6 +2,7 @@
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/spi.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/drivers/display.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
|
||||
#include "epaper/epaper.h"
|
||||
@ -22,11 +23,20 @@ static const struct gpio_dt_spec epd_reset = GPIO_DT_SPEC_GET(EPD_NODE, reset_gp
|
||||
static const struct gpio_dt_spec epd_busy = GPIO_DT_SPEC_GET(EPD_NODE, busy_gpios);
|
||||
|
||||
// SPI
|
||||
const struct device *spi_dev = DEVICE_DT_GET(SPI_BUS);
|
||||
static const struct device *spi_dev = DEVICE_DT_GET(SPI_BUS);
|
||||
|
||||
static struct display_buffer_descriptor desc = {
|
||||
.width = 250,
|
||||
.height = 122,
|
||||
.pitch = 32, // WICHTIG!
|
||||
.buf_size = 3904,
|
||||
};
|
||||
|
||||
static struct spi_config spi_cfg = {
|
||||
.frequency = 4000000,
|
||||
.frequency = 2000000,
|
||||
.operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8) | SPI_TRANSFER_MSB,
|
||||
.cs = NULL,
|
||||
.cs = NULL//{.gpio = {0}}, //war NULL
|
||||
|
||||
};
|
||||
|
||||
// GPIO Makros
|
||||
@ -38,6 +48,12 @@ static struct spi_config spi_cfg = {
|
||||
#define EPD_W21_RST_1 gpio_pin_set_dt(&epd_reset, 1)
|
||||
#define isEPD_W21_BUSY gpio_pin_get_dt(&epd_busy)
|
||||
|
||||
const uint8_t lut_full_update[] = {
|
||||
0x02, 0x02, 0x01, 0x11, 0x10, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Insgesamt 30 Bytes
|
||||
};
|
||||
|
||||
void driver_delay_xms(int32_t xms) {
|
||||
k_msleep(xms);
|
||||
}
|
||||
@ -65,7 +81,7 @@ void Epaper_Spi_WriteByte(uint8_t value) {
|
||||
|
||||
void Epaper_READBUSY(void) {
|
||||
while (isEPD_W21_BUSY) {
|
||||
k_msleep(10);
|
||||
k_msleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,32 +103,40 @@ void Epaper_Write_Data(uint8_t data) {
|
||||
|
||||
void EPD_HW_Init(void) {
|
||||
EPD_W21_RST_0;
|
||||
driver_delay_xms(100);
|
||||
//driver_delay_xms(100);
|
||||
k_msleep(100);
|
||||
EPD_W21_RST_1;
|
||||
driver_delay_xms(100);
|
||||
//driver_delay_xms(100);
|
||||
k_msleep(100);
|
||||
|
||||
Epaper_READBUSY();
|
||||
Epaper_Write_Command(0x12); // SWRESET
|
||||
Epaper_READBUSY();
|
||||
|
||||
Epaper_Write_Command(0x01); // Driver output control
|
||||
Epaper_Write_Data(0xC7);
|
||||
Epaper_Write_Data(0x79); //war C7
|
||||
Epaper_Write_Data(0x00);
|
||||
Epaper_Write_Data(0x00);
|
||||
|
||||
Epaper_Write_Command(0x11); // Data entry mode
|
||||
Epaper_Write_Data(0x01);
|
||||
Epaper_Write_Data(0x03);
|
||||
|
||||
Epaper_Write_Command(0x44); // RAM X start/end
|
||||
Epaper_Write_Data(0x00);
|
||||
Epaper_Write_Data(0x18); //Epaper_Write_Data(0x1F);
|
||||
Epaper_Write_Data(0x1F); //Epaper_Write_Data(0x118);
|
||||
|
||||
Epaper_Write_Command(0x45); // RAM Y start/end
|
||||
Epaper_Write_Data(0xC7);
|
||||
Epaper_Write_Data(0x00); // C7
|
||||
Epaper_Write_Data(0x00);
|
||||
Epaper_Write_Data(0x00);
|
||||
Epaper_Write_Data(0x79);
|
||||
Epaper_Write_Data(0x00);
|
||||
|
||||
Epaper_Write_Command(0X32);
|
||||
for (int i = 0; i < sizeof(lut_full_update); i++) {
|
||||
Epaper_Write_Data(lut_full_update[i]);
|
||||
}
|
||||
Epaper_READBUSY();
|
||||
|
||||
Epaper_Write_Command(0x3C); // BorderWaveform
|
||||
Epaper_Write_Data(0x05);
|
||||
|
||||
@ -122,7 +146,7 @@ void EPD_HW_Init(void) {
|
||||
Epaper_Write_Command(0x4E); // RAM X addr count
|
||||
Epaper_Write_Data(0x00);
|
||||
Epaper_Write_Command(0x4F); // RAM Y addr count
|
||||
Epaper_Write_Data(0xC7);
|
||||
Epaper_Write_Data(0x00); // war C7
|
||||
Epaper_Write_Data(0x00);
|
||||
|
||||
Epaper_READBUSY();
|
||||
@ -130,7 +154,7 @@ void EPD_HW_Init(void) {
|
||||
|
||||
void EPD_Update(void) {
|
||||
Epaper_Write_Command(0x22);
|
||||
Epaper_Write_Data(0xFF);
|
||||
Epaper_Write_Data(0xFF); //Testweise, war FF
|
||||
Epaper_Write_Command(0x20);
|
||||
Epaper_READBUSY();
|
||||
}
|
||||
@ -151,16 +175,11 @@ void EPD_WhiteScreen_Black(void) {
|
||||
EPD_Update();
|
||||
}
|
||||
|
||||
void EPD_WhiteScreen_ALL(const unsigned char *datas) {
|
||||
/* Epaper_Write_Command(0x4E); // Set RAM x address to 0
|
||||
Epaper_Write_Data(0x00);
|
||||
|
||||
Epaper_Write_Command(0x4F); // Set RAM y address to 0
|
||||
Epaper_Write_Data(0x00); // 199 in Dezimal war C7
|
||||
Epaper_Write_Data(0x00);
|
||||
Epaper_READBUSY();*/
|
||||
void EPD_WhiteScreen_ALL(const uint8_t *datas) {
|
||||
//schreiben
|
||||
Epaper_Write_Command(0x24); // Command: write RAM for black/white image
|
||||
|
||||
printk("Data[0] = 0x%02X, Data[1] = 0x%02X\n", datas[0], datas[1]);
|
||||
for (int i = 0; i < ALLSCREEN_GRAGHBYTES; i++) {
|
||||
Epaper_Write_Data(datas[i]);
|
||||
}
|
||||
@ -168,7 +187,8 @@ void EPD_WhiteScreen_ALL(const unsigned char *datas) {
|
||||
EPD_Update(); // Display aktualisieren
|
||||
}
|
||||
|
||||
void draw_something(int num) {
|
||||
|
||||
void draw_something(char toDraw) {
|
||||
printk("E-Paper Init...\n");
|
||||
|
||||
if (!device_is_ready(spi_dev) ||
|
||||
@ -186,25 +206,28 @@ void draw_something(int num) {
|
||||
gpio_pin_configure_dt(&epd_busy, GPIO_INPUT);
|
||||
|
||||
EPD_HW_Init();
|
||||
//EPD_WhiteScreen_Black();
|
||||
int i;
|
||||
for(i = 0; i<22; i++){
|
||||
EPD_WhiteScreen_White();
|
||||
driver_delay_xms(500);
|
||||
}
|
||||
//driver_delay_xms(2000);
|
||||
|
||||
printk("Draw: %d!\n", num);
|
||||
|
||||
switch(num) {
|
||||
case 1: EPD_WhiteScreen_ALL(__01_one_pixel_top_left_bin); break;
|
||||
case 2: EPD_WhiteScreen_ALL(__02_horizontal_top_bin); break;
|
||||
case 3: EPD_WhiteScreen_ALL(__03_vertical_left_bin); break;
|
||||
case 4: EPD_WhiteScreen_ALL(__04_diagonal_bin); break;
|
||||
case 5: EPD_WhiteScreen_ALL(__05_border_frame_bin); break;
|
||||
default: EPD_WhiteScreen_Black; break;
|
||||
static uint8_t testbuffer[ALLSCREEN_GRAGHBYTES];
|
||||
for (int i = 0; i < ALLSCREEN_GRAGHBYTES; i++) {
|
||||
testbuffer[i] = (i % 2 == 0) ? 0xAA : 0x55;
|
||||
}
|
||||
|
||||
|
||||
EPD_WhiteScreen_Black();
|
||||
k_msleep(2000);
|
||||
EPD_WhiteScreen_White();
|
||||
k_msleep(2000);
|
||||
EPD_HW_Init();
|
||||
EPD_WhiteScreen_ALL(testbuffer);
|
||||
|
||||
|
||||
/*switch(toDraw) {
|
||||
case '1': EPD_WhiteScreen_ALL(__01_one_pixel_top_left_bin); break;
|
||||
case '2': EPD_WhiteScreen_ALL(__02_horizontal_top_bin); break;
|
||||
case '3': EPD_WhiteScreen_ALL(__03_vertical_left_bin); break;
|
||||
case '4': EPD_WhiteScreen_ALL(__04_diagonal_bin); break;
|
||||
case '5': EPD_WhiteScreen_ALL(__05_border_frame_bin); break;
|
||||
default: EPD_WhiteScreen_Black(); break;
|
||||
}*/
|
||||
|
||||
printk("Display-Finish!\n");
|
||||
return;
|
||||
|
@ -12,6 +12,15 @@
|
||||
#include "lora/synch.h"
|
||||
|
||||
|
||||
K_WORK_DEFINE(sync_work, synchronite);
|
||||
|
||||
// Sync-Variablen
|
||||
uint32_t offsets[MAX_SAMPLES];
|
||||
uint8_t offset_count = 0;
|
||||
uint32_t sync_offset = 0;
|
||||
uint32_t sync_offset_s = 0;
|
||||
uint32_t samples[MAX_SAMPLES];
|
||||
|
||||
BUILD_ASSERT(DT_NODE_HAS_STATUS_OKAY(DEFAULT_RADIO_NODE),
|
||||
"No default LoRa radio specified in DT");
|
||||
|
||||
@ -56,9 +65,6 @@ void lora_receive_cb(const struct device *dev, uint8_t *data, uint16_t size,
|
||||
}
|
||||
}
|
||||
}
|
||||
gpio_pin_set_dt(&led_blue, 1);
|
||||
}else{
|
||||
gpio_pin_set_dt(&led_blue, 0);
|
||||
|
||||
// 🕒 Hilfsfunktion: synchronisierter Timerwert
|
||||
uint32_t get_synced_timer() {
|
||||
|
21
src/main.c
21
src/main.c
@ -1,14 +1,16 @@
|
||||
#include <stdint.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
|
||||
#include "epaper/epaper.h"
|
||||
#include "oled/oled.h"
|
||||
|
||||
#include "utils/buttons.h"
|
||||
#include "utils/leds.h"
|
||||
#include "utils/constAndVars.h"
|
||||
|
||||
|
||||
// ⚙️ GPIO Initialisierung
|
||||
int init_led_and_button(void) {
|
||||
int ret;
|
||||
uint8_t init_led_and_button(void) {
|
||||
uint8_t ret;
|
||||
|
||||
if (!gpio_is_ready_dt(&led_green)) return -1;
|
||||
ret = gpio_pin_configure_dt(&led_green, GPIO_OUTPUT_INACTIVE);
|
||||
@ -35,12 +37,13 @@ int main(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
while(1){
|
||||
/*while(1){
|
||||
if(nextSynchro > 0){
|
||||
uint32_t sleepTimer = local_now - nextsynchro;
|
||||
sleep(sleepTimer);
|
||||
uint32_t sleepTimer = k_uptime_get() - nextSynchro;
|
||||
k_msleep(sleepTimer);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
draw_something(4);
|
||||
char toDraw = '4';
|
||||
oled_draw_something(toDraw);
|
||||
}
|
||||
|
214
src/oled/oled.c
Normal file
214
src/oled/oled.c
Normal file
@ -0,0 +1,214 @@
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/spi.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/drivers/display.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
|
||||
#include "oled/oled.h"
|
||||
|
||||
#define OLED_NODE DT_NODELABEL(oled)
|
||||
#define SPI_BUS DT_BUS(OLED_NODE)
|
||||
|
||||
// GPIOs
|
||||
static const struct gpio_dt_spec oled_cs = GPIO_DT_SPEC_GET(OLED_NODE, cs_gpios);
|
||||
static const struct gpio_dt_spec oled_dc = GPIO_DT_SPEC_GET(OLED_NODE, dc_gpios);
|
||||
static const struct gpio_dt_spec oled_reset = GPIO_DT_SPEC_GET(OLED_NODE, reset_gpios);
|
||||
|
||||
// SPI
|
||||
static const struct device *spi_dev = DEVICE_DT_GET(SPI_BUS);
|
||||
|
||||
static struct display_buffer_descriptor desc = {
|
||||
.width = 128,
|
||||
.height = 64,
|
||||
.pitch = 16, // WICHTIG!
|
||||
.buf_size = 1024,
|
||||
};
|
||||
|
||||
static const struct spi_dt_spec spi_oled = SPI_DT_SPEC_GET(OLED_NODE,
|
||||
SPI_OP_MODE_MASTER | SPI_WORD_SET(8) | SPI_TRANSFER_MSB,
|
||||
2000000);
|
||||
|
||||
///static struct spi_config spi_cfg = {
|
||||
/// .frequency = 2000000,
|
||||
/// .operation = SPI_OP_MODE_MASTER | SPI_WORD_SET(8) | SPI_TRANSFER_MSB,
|
||||
// .cs = NULL//{.gpio = {0}}, //war NULL
|
||||
|
||||
//};
|
||||
|
||||
// GPIO Makros
|
||||
#define OLED_CS_0 gpio_pin_set_dt(&oled_cs, 0)
|
||||
#define OLED_CS_1 gpio_pin_set_dt(&oled_cs, 1)
|
||||
#define OLED_DC_0 gpio_pin_set_dt(&oled_dc, 0)
|
||||
#define OLED_DC_1 gpio_pin_set_dt(&oled_dc, 1)
|
||||
#define OLED_RST_0 gpio_pin_set_dt(&oled_reset, 0)
|
||||
#define OLED_RST_1 gpio_pin_set_dt(&oled_reset, 1)
|
||||
|
||||
void oled_driver_delay_xms(int32_t xms) {
|
||||
k_msleep(xms);
|
||||
}
|
||||
|
||||
void OLED_Spi_WriteByte(uint8_t value) {
|
||||
uint8_t tx_data[1] = { value };
|
||||
struct spi_buf buf = {
|
||||
.buf = tx_data,
|
||||
.len = 1
|
||||
};
|
||||
struct spi_buf_set tx = {
|
||||
.buffers = &buf,
|
||||
.count = 1
|
||||
};
|
||||
spi_write_dt(&spi_oled, &tx);
|
||||
}
|
||||
|
||||
void OLED_Spi_WriteBuffer(uint8_t *data, size_t len) {
|
||||
struct spi_buf buf = {
|
||||
.buf = data,
|
||||
.len = len
|
||||
};
|
||||
struct spi_buf_set tx = {
|
||||
.buffers = &buf,
|
||||
.count = 1
|
||||
};
|
||||
spi_write_dt(&spi_oled, &tx);
|
||||
}
|
||||
|
||||
|
||||
void OLED_Write_Command(uint8_t cmd) {
|
||||
OLED_DC_0;
|
||||
OLED_CS_0;
|
||||
OLED_Spi_WriteByte(cmd);
|
||||
OLED_CS_1;
|
||||
}
|
||||
|
||||
void OLED_Write_Data(uint8_t *data, size_t len) {
|
||||
OLED_DC_1;
|
||||
OLED_CS_0;
|
||||
OLED_Spi_WriteBuffer(data, len);
|
||||
OLED_CS_1;
|
||||
}
|
||||
|
||||
void OLED_HW_Init(void) {
|
||||
OLED_Reset();
|
||||
|
||||
OLED_Write_Command(0xAE); // Display OFF
|
||||
|
||||
OLED_Write_Command(0xD5); // Set Display Clock Divide Ratio
|
||||
OLED_Write_Command(0x80);
|
||||
|
||||
OLED_Write_Command(0xA8); // Set Multiplex Ratio
|
||||
OLED_Write_Command(0x3F); // 0x3F = 64 (für 64 Zeilen)
|
||||
|
||||
OLED_Write_Command(0xD3); // Set Display Offset
|
||||
OLED_Write_Command(0x00);
|
||||
|
||||
OLED_Write_Command(0x40); // Set Display Start Line to 0
|
||||
|
||||
OLED_Write_Command(0x8D); // Charge Pump
|
||||
OLED_Write_Command(0x14);
|
||||
|
||||
OLED_Write_Command(0x20); // Memory addressing mode
|
||||
OLED_Write_Command(0x00); // Horizontal addressing
|
||||
|
||||
OLED_Write_Command(0xA1); // Segment remap (flip horizontally)
|
||||
OLED_Write_Command(0xC8); // COM Output Scan Direction (flip vertically)
|
||||
|
||||
OLED_Write_Command(0xDA); // COM pins config
|
||||
OLED_Write_Command(0x12);
|
||||
|
||||
OLED_Write_Command(0x81); // Contrast
|
||||
OLED_Write_Command(0x7F);
|
||||
|
||||
OLED_Write_Command(0xD9); // Pre-charge
|
||||
OLED_Write_Command(0xF1);
|
||||
|
||||
OLED_Write_Command(0xDB); // VCOMH Deselect Level
|
||||
OLED_Write_Command(0x40);
|
||||
|
||||
OLED_Write_Command(0xA4); // Entire Display ON from RAM
|
||||
OLED_Write_Command(0xA6); // Normal (nicht invertiert)
|
||||
|
||||
OLED_Write_Command(0xAF); // Display ON
|
||||
|
||||
}
|
||||
|
||||
void OLED_Reset(void) {
|
||||
OLED_RST_0;
|
||||
oled_driver_delay_xms(10);
|
||||
OLED_RST_1;
|
||||
oled_driver_delay_xms(10);
|
||||
}
|
||||
|
||||
void OLED_WhiteScreen_White(void) {
|
||||
uint8_t ones[128];
|
||||
memset(ones, 0xFF, sizeof(ones));
|
||||
for (uint8_t page = 0; page < 8; page++) {
|
||||
OLED_Write_Command(0xB0 + page); // Page Address
|
||||
OLED_Write_Command(0x00); // Lower column start
|
||||
OLED_Write_Command(0x10); // Higher column start
|
||||
OLED_Write_Data(ones, 128); // Leere Zeile senden
|
||||
}
|
||||
}
|
||||
|
||||
void OLED_WhiteScreen_Black(void) {
|
||||
uint8_t zeros[128] = {0}; // Eine Zeile mit 128 Pixeln
|
||||
for (uint8_t page = 0; page < 8; page++) {
|
||||
OLED_Write_Command(0xB0 + page); // Page Address
|
||||
OLED_Write_Command(0x00); // Lower column start
|
||||
OLED_Write_Command(0x10); // Higher column start
|
||||
OLED_Write_Data(zeros, 128); // Leere Zeile senden
|
||||
}
|
||||
}
|
||||
|
||||
void OLED_WhiteScreen_ALL(const uint8_t *datas) {
|
||||
for (uint8_t page = 0; page < 8; page++) {
|
||||
OLED_Write_Command(0xB0 + page); // Page
|
||||
OLED_Write_Command(0x00); // Column low
|
||||
OLED_Write_Command(0x10); // Column high
|
||||
OLED_Write_Data((uint8_t *)(datas + (128 * page)), 128);
|
||||
}
|
||||
}
|
||||
|
||||
void oled_draw_something(char toDraw) {
|
||||
printk("OLED Init...\n");
|
||||
|
||||
if (!device_is_ready(spi_dev) ||
|
||||
!device_is_ready(oled_cs.port) ||
|
||||
!device_is_ready(oled_dc.port) ||
|
||||
!device_is_ready(oled_reset.port)) {
|
||||
printk("Gerät nicht bereit\n");
|
||||
return;
|
||||
}
|
||||
|
||||
gpio_pin_configure_dt(&oled_cs, GPIO_OUTPUT_ACTIVE);
|
||||
gpio_pin_configure_dt(&oled_dc, GPIO_OUTPUT_ACTIVE);
|
||||
gpio_pin_configure_dt(&oled_reset, GPIO_OUTPUT_ACTIVE);
|
||||
|
||||
|
||||
OLED_HW_Init();
|
||||
|
||||
static uint8_t testbuffer[ALLSCREEN_GRAGHBYTES];
|
||||
for (int i = 0; i < ALLSCREEN_GRAGHBYTES; i++) {
|
||||
testbuffer[i] = (i % 2 == 0) ? 0xAA : 0x55;
|
||||
}
|
||||
|
||||
OLED_WhiteScreen_Black();
|
||||
k_msleep(2000);
|
||||
OLED_WhiteScreen_White();
|
||||
k_msleep(2000);
|
||||
OLED_HW_Init();
|
||||
OLED_WhiteScreen_ALL(testbuffer);
|
||||
|
||||
|
||||
/*switch(toDraw) {
|
||||
case '1': EPD_WhiteScreen_ALL(__01_one_pixel_top_left_bin); break;
|
||||
case '2': EPD_WhiteScreen_ALL(__02_horizontal_top_bin); break;
|
||||
case '3': EPD_WhiteScreen_ALL(__03_vertical_left_bin); break;
|
||||
case '4': EPD_WhiteScreen_ALL(__04_diagonal_bin); break;
|
||||
case '5': EPD_WhiteScreen_ALL(__05_border_frame_bin); break;
|
||||
default: EPD_WhiteScreen_Black(); break;
|
||||
}*/
|
||||
|
||||
printk("Display-Finish!\n");
|
||||
return;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
#include "utils/buttons.h"
|
||||
|
||||
const struct gpio_dt_spec button0 = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios, {0});
|
6
src/utils/constAndVars.c
Normal file
6
src/utils/constAndVars.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include "utils/constAndVars.h"
|
||||
|
||||
bool slave = false;
|
||||
bool error = false;
|
||||
uint32_t nextSynchro = -1;
|
||||
bool synchronized = false;
|
@ -1,5 +1,7 @@
|
||||
#include "utils/leds.h"
|
||||
|
||||
const struct gpio_dt_spec led_green = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
|
||||
|
||||
void turnOutLEDS(void){
|
||||
gpio_pin_set_dt(&led_green, 0);
|
||||
//gpio_pin_set_dt(&led_red, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user