Transfer spi into c++

This commit is contained in:
Thomas Klaehn
2020-03-29 20:43:56 +02:00
parent 7f1721a536
commit 53aa3ceda6
17 changed files with 131 additions and 4899 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +0,0 @@
#ifndef __BOARD_H__
#define __BOARD_H__
#if defined(BOARD_PCA10040)
#include "platform/nrf52/nrf52-dk.h"
#endif
#endif

View File

@@ -1,34 +0,0 @@
#ifndef __DRIVER_H__
#define __DRIVER_H__
#include <stdarg.h>
struct driver;
typedef int (*fp_open_t)(const struct driver *);
typedef int (*fp_close_t)(const struct driver *);
typedef int (*fp_read_t)(const struct driver *, char *, unsigned int);
typedef int (*fp_write_t)(const struct driver *, const char *, unsigned int);
typedef int (*fp_ioctl_t)(const struct driver *, unsigned int, unsigned int argc, va_list);
struct driver_fp {
fp_open_t open;
fp_close_t close;
fp_read_t read;
fp_write_t write;
fp_ioctl_t ioctl;
};
struct driver {
const char *name;
const struct driver_fp *fp;
const void *dev;
};
int drv_open(const struct driver *drv);
int drv_close(const struct driver *drv);
int drv_read(const struct driver *drv, char *buffer, unsigned int length);
int drv_write(const struct driver *drv, const char *buffer, unsigned int length);
int drv_ioctl(const struct driver *drv, unsigned int cmd, unsigned int argc, ...);
#endif

View File

@@ -1,12 +0,0 @@
#ifndef __INCLUDE_FRAMEBUFFER_H__
#define __INCLUDE_FRAMEBUFFER_H__
#include <stdint.h>
void fb_draw_pixel(uint16_t *image, uint16_t x, uint16_t y, uint16_t color);
void fb_draw_line(uint16_t *image, int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
void fb_load_image(uint16_t *dst, uint16_t *src, uint32_t length);
void fb_set_image(uint16_t *dst, uint16_t value, uint32_t length);
#endif

View File

@@ -1,34 +0,0 @@
#ifndef __GPIO_H__
#define __GPIO_H__
#include <stdarg.h>
#include "driver.h"
#define IOCTL_CMD_SET_DIRECTION 0
int gpio_open(const struct driver *drv);
int gpio_close(const struct driver *drv);
int gpio_read(const struct driver *drv, char *buffer, unsigned int len);
int gpio_write(const struct driver *drv, const char *buffer, unsigned int len);
enum direction {
IN = 0,
OUT
};
struct gpio {
int pin;
enum direction dir;
};
static const struct driver_fp gpio_fp = {
.open = gpio_open,
.close = gpio_close,
.read = gpio_read,
.write = gpio_write,
.ioctl = NULL
};
#endif

View File

@@ -1,117 +0,0 @@
#ifndef __NRF52_DK_H__
#define __NRF52_DK_H__
#include "driver.h"
#include "gpio.h"
#include "spi.h"
#include "st7789.h"
// LED 1
const struct gpio nrf_led_1 = {
.pin = 17,
.dir = OUT
};
const struct driver led_1 = {
.name = "LED1",
.fp = &gpio_fp,
.dev = &nrf_led_1
};
// LED 2
const struct gpio nrf_led_2 = {
.pin = 18,
.dir = OUT
};
const struct driver led_2 = {
.name = "LED2",
.fp = &gpio_fp,
.dev = &nrf_led_2
};
// LED 3
const struct gpio nrf_led_3 = {
.pin = 19,
.dir = OUT
};
const struct driver led_3 = {
.name = "LED3",
.fp = &gpio_fp,
.dev = &nrf_led_3
};
// LED 4
const struct gpio nrf_led_4 = {
.pin = 20,
.dir = OUT
};
const struct driver led_4 = {
.name = "LED4",
.fp = &gpio_fp,
.dev = &nrf_led_4
};
// LCD
// SPI 0
const struct spi nrf_spi_0 = {
.sck_pin = 2,
.mosi_pin = 3,
.miso_pin = 4
};
const struct driver spi_0 = {
.name = "SPI0",
.fp = &spi_fp,
.dev = &nrf_spi_0
};
const struct gpio nrf_dc_pin = {
.pin = 18,
.dir = OUT
};
const struct driver dc_pin = {
.name = "DC",
.fp = &gpio_fp,
.dev = &nrf_dc_pin
};
const struct gpio nrf_bl_pin = {
.pin = 23,
.dir = OUT
};
const struct driver bl_pin = {
.name = "BACKLIGHT",
.fp = &gpio_fp,
.dev = &nrf_bl_pin
};
const struct gpio nrf_rst_pin = {
.pin = 26,
.dir = OUT
};
const struct driver rst_pin = {
.name = "RESET",
.fp = &gpio_fp,
.dev = &nrf_rst_pin
};
const struct gpio nrf_select_pin = {
.pin = 25,
.dir = OUT
};
const struct driver select_pin = {
.name = "SELECT",
.fp = &gpio_fp,
.dev = &nrf_select_pin
};
struct st7789 nrf_lcd = {
.spi = &spi_0,
.dc = &dc_pin,
.bl = &bl_pin,
.rst = &rst_pin,
.select = &select_pin,
.height = 240,
.width = 240,
};
const struct driver lcd = {
.name = "LCD",
.fp = &st7789_fp,
.dev = &nrf_lcd
};
#endif

View File

@@ -1,23 +0,0 @@
#ifndef __NRF52_SPI_H__
#define __NRF52_SPI_H__
int spi_open(const struct driver *drv);
int spi_close(const struct driver *drv);
int spi_write(const struct driver *drv, const char *buffer, unsigned int len);
struct spi {
unsigned int sck_pin;
unsigned int mosi_pin;
unsigned int miso_pin;
};
static const struct driver_fp spi_fp = {
.open = spi_open,
.close = spi_close,
.read = NULL,
.write = spi_write,
.ioctl = NULL
};
#endif