93 lines
2.7 KiB
C
Executable File
93 lines
2.7 KiB
C
Executable File
#include <stdlib.h>
|
|
|
|
#include "stm32f4xx_hal.h"
|
|
|
|
#include "fonts.h"
|
|
|
|
#ifndef ssd1306
|
|
#define ssd1306
|
|
|
|
// i2c port naam in main programma gegenereerd door cube
|
|
#define SSD1306_I2C_PORT hi2c1
|
|
// I2C address
|
|
#define SSD1306_I2C_ADDR 0x78
|
|
// SSD1306 width in pixels
|
|
#define SSD1306_WIDTH 128
|
|
// SSD1306 LCD height in pixels
|
|
#define SSD1306_HEIGHT 64
|
|
|
|
#define SSD1306_EXTERNALVCC 0x1
|
|
#define SSD1306_SWITCHCAPVCC 0x2
|
|
#define SSD1306_SETCONTRAST 0x81
|
|
#define SSD1306_DISPLAYALLON_RESUME 0xA4
|
|
#define SSD1306_DISPLAYALLON 0xA5
|
|
#define SSD1306_NORMALDISPLAY 0xA6
|
|
#define SSD1306_INVERTDISPLAY 0xA7
|
|
#define SSD1306_DISPLAYOFF 0xAE
|
|
#define SSD1306_DISPLAYON 0xAF
|
|
#define SSD1306_SETDISPLAYOFFSET 0xD3
|
|
#define SSD1306_SETCOMPINS 0xDA
|
|
#define SSD1306_SETVCOMDETECT 0xDB
|
|
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
|
|
#define SSD1306_SETPRECHARGE 0xD9
|
|
#define SSD1306_SETMULTIPLEX 0xA8
|
|
#define SSD1306_SETLOWCOLUMN 0x00
|
|
#define SSD1306_SETHIGHCOLUMN 0x10
|
|
#define SSD1306_SETSTARTLINE 0x40
|
|
#define SSD1306_MEMORYMODE 0x20
|
|
#define SSD1306_COLUMNADDR 0x21
|
|
#define SSD1306_PAGEADDR 0x22
|
|
#define SSD1306_COMSCANINC 0xC0
|
|
#define SSD1306_COMSCANDEC 0xC8
|
|
#define SSD1306_SEGREMAP 0xA0
|
|
#define SSD1306_CHARGEPUMP 0x8D
|
|
|
|
// Scrolling #defines
|
|
#define SSD1306_ACTIVATE_SCROLL 0x2F
|
|
#define SSD1306_DEACTIVATE_SCROLL 0x2E
|
|
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3
|
|
#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26
|
|
#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27
|
|
#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
|
|
#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
|
|
|
|
#ifndef _swap_int16_t
|
|
#define _swap_int16_t(a, b) { int16_t t = a; a = b; b = t; }
|
|
#endif
|
|
|
|
//
|
|
// Enum voor de kleuren van het scherm Black en White
|
|
//
|
|
typedef enum {
|
|
Black = 0x00, /*!< Black color, no pixel */
|
|
White = 0x01 /*!< Pixel is set. Color depends on LCD */
|
|
} SSD1306_COLOR;
|
|
|
|
//
|
|
// Struct om wijzigingen bij te houden
|
|
//
|
|
typedef struct {
|
|
uint16_t CurrentX;
|
|
uint16_t CurrentY;
|
|
uint8_t Inverted;
|
|
uint8_t Initialized;
|
|
} SSD1306_t;
|
|
|
|
// De i2c poort staat in de main
|
|
extern I2C_HandleTypeDef SSD1306_I2C_PORT;
|
|
|
|
//
|
|
// De functies definities van de functies die gebruikt kunnen worden
|
|
//
|
|
uint8_t ssd1306_Init(void);
|
|
void ssd1306_Fill(SSD1306_COLOR color);
|
|
void ssd1306_UpdateScreen(void);
|
|
void ssd1306_DrawPixel(uint8_t x, uint8_t y, SSD1306_COLOR color);
|
|
char ssd1306_WriteChar(char ch, FontDef Font, SSD1306_COLOR color);
|
|
char ssd1306_WriteString(char* str, FontDef Font, SSD1306_COLOR color);
|
|
void ssd1306_SetCursor(uint8_t x, uint8_t y);
|
|
void ssd1306_WriteCommand(uint8_t command);
|
|
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1);
|
|
|
|
#endif
|