Pixel by pixel scrolling
This commit is contained in:
parent
af1ad437ac
commit
3ae85de2d9
|
@ -2,23 +2,11 @@
|
||||||
#include "stm32f4xx_hal.h"
|
#include "stm32f4xx_hal.h"
|
||||||
#include "fonts.h"
|
#include "fonts.h"
|
||||||
|
|
||||||
// Deze library is door Olivier Van den Eede 2016 geschreven en aangepast voor gebruik met
|
|
||||||
// Stm32 microcontrollers en maakt gebruik van de HAL-i2c library's.
|
|
||||||
//
|
|
||||||
// Deze library is gemaakt om gebruik te kunnen maken van een ssd1306 gestuurd oled display.
|
|
||||||
// Voor het gebruik moeten zeker de onderstaande defines juist ingesteld worden.
|
|
||||||
// Zoals de gebruikte i2c poort en de groote van het scherm.
|
|
||||||
//
|
|
||||||
// De library maakt gebruik van 2 files (fonts.c/h) Hierin staan 3 fonts beschreven.
|
|
||||||
// Deze fonts kunnen zo gebruikt worden: - Font_7x10
|
|
||||||
// - Font_11x18
|
|
||||||
// - Font_16x26
|
|
||||||
|
|
||||||
#ifndef ssd1306
|
#ifndef ssd1306
|
||||||
#define ssd1306
|
#define ssd1306
|
||||||
|
|
||||||
// i2c port naam in main programma gegenereerd door cube
|
// i2c port naam in main programma gegenereerd door cube
|
||||||
#define SSD1306_I2C_PORT hi2c1
|
#define SSD1306_I2C_PORT hi2c1
|
||||||
// I2C address
|
// I2C address
|
||||||
#define SSD1306_I2C_ADDR 0x78
|
#define SSD1306_I2C_ADDR 0x78
|
||||||
// SSD1306 width in pixels
|
// SSD1306 width in pixels
|
||||||
|
@ -26,30 +14,64 @@
|
||||||
// SSD1306 LCD height in pixels
|
// SSD1306 LCD height in pixels
|
||||||
#define SSD1306_HEIGHT 64
|
#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
|
||||||
|
|
||||||
//
|
//
|
||||||
// Enum voor de kleuren van het scherm Black en White
|
// Enum voor de kleuren van het scherm Black en White
|
||||||
//
|
//
|
||||||
typedef enum {
|
typedef enum {
|
||||||
Black = 0x00, /*!< Black color, no pixel */
|
Black = 0x00, /*!< Black color, no pixel */
|
||||||
White = 0x01 /*!< Pixel is set. Color depends on LCD */
|
White = 0x01 /*!< Pixel is set. Color depends on LCD */
|
||||||
} SSD1306_COLOR;
|
} SSD1306_COLOR;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Struct om wijzigingen bij te houden
|
// Struct om wijzigingen bij te houden
|
||||||
//
|
//
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t CurrentX;
|
uint16_t CurrentX;
|
||||||
uint16_t CurrentY;
|
uint16_t CurrentY;
|
||||||
uint8_t Inverted;
|
uint8_t Inverted;
|
||||||
uint8_t Initialized;
|
uint8_t Initialized;
|
||||||
} SSD1306_t;
|
} SSD1306_t;
|
||||||
|
|
||||||
// De i2c poort staat in de main
|
// De i2c poort staat in de main
|
||||||
extern I2C_HandleTypeDef SSD1306_I2C_PORT;
|
extern I2C_HandleTypeDef SSD1306_I2C_PORT;
|
||||||
|
|
||||||
//
|
//
|
||||||
// De functies definities van de functies die gebruikt kunnen worden
|
// De functies definities van de functies die gebruikt kunnen worden
|
||||||
//
|
//
|
||||||
uint8_t ssd1306_Init(void);
|
uint8_t ssd1306_Init(void);
|
||||||
void ssd1306_Fill(SSD1306_COLOR color);
|
void ssd1306_Fill(SSD1306_COLOR color);
|
||||||
|
@ -60,5 +82,7 @@ char ssd1306_WriteString(char* str, FontDef Font, SSD1306_COLOR color);
|
||||||
void ssd1306_SetCursor(uint8_t x, uint8_t y);
|
void ssd1306_SetCursor(uint8_t x, uint8_t y);
|
||||||
|
|
||||||
void ssd1306_WriteCommand(uint8_t command);
|
void ssd1306_WriteCommand(uint8_t command);
|
||||||
|
void ssd1306_Scroll(void);
|
||||||
|
void startscrollright(uint8_t start, uint8_t stop);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
650
Src/main.c
650
Src/main.c
|
@ -1,319 +1,331 @@
|
||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* File Name : main.c
|
* File Name : main.c
|
||||||
* Description : Main program body
|
* Description : Main program body
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*
|
*
|
||||||
* COPYRIGHT(c) 2017 STMicroelectronics
|
* COPYRIGHT(c) 2017 STMicroelectronics
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
* are permitted provided that the following conditions are met:
|
* are permitted provided that the following conditions are met:
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer.
|
* this list of conditions and the following disclaimer.
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
* and/or other materials provided with the distribution.
|
* and/or other materials provided with the distribution.
|
||||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "main.h"
|
#include <stdlib.h>
|
||||||
#include "stm32f4xx_hal.h"
|
|
||||||
|
#include "main.h"
|
||||||
/* USER CODE BEGIN Includes */
|
#include "stm32f4xx_hal.h"
|
||||||
#include "ssd1306.h"
|
|
||||||
#include "fonts.h"
|
/* USER CODE BEGIN Includes */
|
||||||
|
#include "ssd1306.h"
|
||||||
//#include "dht22.h"
|
#include "fonts.h"
|
||||||
|
//#include "dht22.h"
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
I2C_HandleTypeDef hi2c1;
|
I2C_HandleTypeDef hi2c1;
|
||||||
|
UART_HandleTypeDef huart1;
|
||||||
UART_HandleTypeDef huart1;
|
|
||||||
|
/* USER CODE BEGIN PV */
|
||||||
/* USER CODE BEGIN PV */
|
/* Private variables ---------------------------------------------------------*/
|
||||||
/* Private variables ---------------------------------------------------------*/
|
char UART1_Data;
|
||||||
char UART1_Data;
|
char UART_Buffer[32];
|
||||||
char UART_Buffer[32];
|
char text[32];
|
||||||
char text[32];
|
int i;
|
||||||
unsigned char i = 0;
|
|
||||||
|
/* USER CODE END PV */
|
||||||
/* USER CODE END PV */
|
|
||||||
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
void SystemClock_Config(void);
|
||||||
void SystemClock_Config(void);
|
void Error_Handler(void);
|
||||||
void Error_Handler(void);
|
static void MX_GPIO_Init(void);
|
||||||
static void MX_GPIO_Init(void);
|
static void MX_I2C1_Init(void);
|
||||||
static void MX_I2C1_Init(void);
|
static void MX_USART1_UART_Init(void);
|
||||||
static void MX_USART1_UART_Init(void);
|
|
||||||
|
/* USER CODE BEGIN PFP */
|
||||||
/* USER CODE BEGIN PFP */
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
|
||||||
|
/* USER CODE END PFP */
|
||||||
/* USER CODE END PFP */
|
|
||||||
|
/* USER CODE BEGIN 0 */
|
||||||
/* USER CODE BEGIN 0 */
|
|
||||||
|
/* USER CODE END 0 */
|
||||||
/* USER CODE END 0 */
|
|
||||||
|
int main(void)
|
||||||
int main(void)
|
{
|
||||||
{
|
/* USER CODE BEGIN 1 */
|
||||||
/* USER CODE BEGIN 1 */
|
|
||||||
|
/* USER CODE END 1 */
|
||||||
/* USER CODE END 1 */
|
|
||||||
|
/* MCU Configuration----------------------------------------------------------*/
|
||||||
/* MCU Configuration----------------------------------------------------------*/
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
HAL_Init();
|
||||||
HAL_Init();
|
|
||||||
|
/* Configure the system clock */
|
||||||
/* Configure the system clock */
|
SystemClock_Config();
|
||||||
SystemClock_Config();
|
|
||||||
|
/* Initialize all configured peripherals */
|
||||||
/* Initialize all configured peripherals */
|
MX_GPIO_Init();
|
||||||
MX_GPIO_Init();
|
MX_I2C1_Init();
|
||||||
MX_I2C1_Init();
|
MX_USART1_UART_Init();
|
||||||
MX_USART1_UART_Init();
|
|
||||||
|
/* USER CODE BEGIN 2 */
|
||||||
/* USER CODE BEGIN 2 */
|
ssd1306_Init();
|
||||||
ssd1306_Init();
|
//DHT22_Init();
|
||||||
//DHT22_Init();
|
HAL_UART_Receive_IT(&huart1, (uint8_t*) &UART1_Data, 1);
|
||||||
HAL_UART_Receive_IT(&huart1, (uint8_t*) &UART1_Data, 1);
|
|
||||||
/* USER CODE END 2 */
|
/*
|
||||||
|
for(int y = 0; y < 129; y++) {
|
||||||
/* Infinite loop */
|
ssd1306_DrawPixel(y, 20, White);
|
||||||
/* USER CODE BEGIN WHILE */
|
}
|
||||||
while (1)
|
*/
|
||||||
{
|
//ssd1306_UpdateScreen();
|
||||||
/* USER CODE END WHILE */
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
/* USER CODE BEGIN 3 */
|
/* Infinite loop */
|
||||||
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_6); //Toggle the state of pin PC9
|
/* USER CODE BEGIN WHILE */
|
||||||
//HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_7); //Toggle the state of pin PC9
|
while (1)
|
||||||
//DHT22_Read(htim6);
|
{
|
||||||
|
/* USER CODE END WHILE */
|
||||||
ssd1306_SetCursor(0, 53);
|
|
||||||
ssd1306_WriteString(text, Font_7x10, White);
|
/* USER CODE BEGIN 3 */
|
||||||
ssd1306_UpdateScreen();
|
int x, msg;
|
||||||
|
//HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_6); //Toggle the state of pin PC9
|
||||||
for(int i = 0; i < 64; i++) {
|
//DHT22_Read(htim6);
|
||||||
ssd1306_WriteCommand(0x40 | i);
|
|
||||||
ssd1306_UpdateScreen();
|
|
||||||
HAL_Delay(30);
|
//startscrollright(0x00, 0x0F);
|
||||||
}
|
|
||||||
|
for(int times = 0; times < 12; times++) {
|
||||||
//HAL_Delay(250);
|
ssd1306_Scroll();
|
||||||
|
ssd1306_UpdateScreen();
|
||||||
ssd1306_Fill(Black);
|
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_7); //Toggle the state of pin PC9
|
||||||
ssd1306_UpdateScreen();
|
}
|
||||||
}
|
|
||||||
/* USER CODE END 3 */
|
x = rand() % 60 + 1;
|
||||||
|
msg = rand() % 2 + 1;
|
||||||
}
|
ssd1306_SetCursor(x, 53);
|
||||||
|
ssd1306_WriteString((msg == 1) ? "GORDOS" : "LOL", Font_7x10, White);
|
||||||
/** System Clock Configuration
|
|
||||||
*/
|
/*
|
||||||
void SystemClock_Config(void)
|
for(int y = 0; y < 129; y++) {
|
||||||
{
|
ssd1306_DrawPixel(y, 63, White);
|
||||||
|
}
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct;
|
*/
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
ssd1306_UpdateScreen();
|
||||||
|
}
|
||||||
/**Configure the main internal regulator output voltage
|
/* USER CODE END 3 */
|
||||||
*/
|
|
||||||
__HAL_RCC_PWR_CLK_ENABLE();
|
}
|
||||||
|
|
||||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
/** System Clock Configuration
|
||||||
|
*/
|
||||||
/**Initializes the CPU, AHB and APB busses clocks
|
void SystemClock_Config(void)
|
||||||
*/
|
{
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
|
||||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
RCC_OscInitTypeDef RCC_OscInitStruct;
|
||||||
RCC_OscInitStruct.HSICalibrationValue = 16;
|
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
/**Configure the main internal regulator output voltage
|
||||||
{
|
*/
|
||||||
Error_Handler();
|
__HAL_RCC_PWR_CLK_ENABLE();
|
||||||
}
|
|
||||||
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
||||||
/**Initializes the CPU, AHB and APB busses clocks
|
|
||||||
*/
|
/**Initializes the CPU, AHB and APB busses clocks
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
*/
|
||||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
RCC_OscInitStruct.HSICalibrationValue = 16;
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
Error_Handler();
|
||||||
{
|
}
|
||||||
Error_Handler();
|
|
||||||
}
|
/**Initializes the CPU, AHB and APB busses clocks
|
||||||
|
*/
|
||||||
/**Configure the Systick interrupt time
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
*/
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
|
||||||
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
/**Configure the Systick
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
||||||
*/
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||||
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
|
|
||||||
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
|
||||||
/* SysTick_IRQn interrupt configuration */
|
{
|
||||||
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* I2C1 init function */
|
/**Configure the Systick interrupt time
|
||||||
static void MX_I2C1_Init(void)
|
*/
|
||||||
{
|
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
|
||||||
|
|
||||||
hi2c1.Instance = I2C1;
|
/**Configure the Systick
|
||||||
hi2c1.Init.ClockSpeed = 400000;
|
*/
|
||||||
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_16_9;
|
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
|
||||||
hi2c1.Init.OwnAddress1 = 0;
|
|
||||||
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
/* SysTick_IRQn interrupt configuration */
|
||||||
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
|
||||||
hi2c1.Init.OwnAddress2 = 0;
|
}
|
||||||
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
|
||||||
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
/* I2C1 init function */
|
||||||
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
|
static void MX_I2C1_Init(void)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
|
||||||
}
|
hi2c1.Instance = I2C1;
|
||||||
|
hi2c1.Init.ClockSpeed = 400000;
|
||||||
}
|
hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_16_9;
|
||||||
|
hi2c1.Init.OwnAddress1 = 0;
|
||||||
/* USART1 init function */
|
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||||
static void MX_USART1_UART_Init(void)
|
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||||
{
|
hi2c1.Init.OwnAddress2 = 0;
|
||||||
|
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||||
huart1.Instance = USART1;
|
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||||
huart1.Init.BaudRate = 9600;
|
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
|
||||||
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
{
|
||||||
huart1.Init.StopBits = UART_STOPBITS_1;
|
Error_Handler();
|
||||||
huart1.Init.Parity = UART_PARITY_NONE;
|
}
|
||||||
huart1.Init.Mode = UART_MODE_TX_RX;
|
|
||||||
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
}
|
||||||
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
||||||
if (HAL_UART_Init(&huart1) != HAL_OK)
|
/* USART1 init function */
|
||||||
{
|
static void MX_USART1_UART_Init(void)
|
||||||
Error_Handler();
|
{
|
||||||
}
|
|
||||||
|
huart1.Instance = USART1;
|
||||||
}
|
huart1.Init.BaudRate = 115200;
|
||||||
|
huart1.Init.WordLength = UART_WORDLENGTH_8B;
|
||||||
/** Configure pins as
|
huart1.Init.StopBits = UART_STOPBITS_1;
|
||||||
* Analog
|
huart1.Init.Parity = UART_PARITY_NONE;
|
||||||
* Input
|
huart1.Init.Mode = UART_MODE_TX_RX;
|
||||||
* Output
|
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
||||||
* EVENT_OUT
|
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
|
||||||
* EXTI
|
if (HAL_UART_Init(&huart1) != HAL_OK)
|
||||||
*/
|
{
|
||||||
static void MX_GPIO_Init(void)
|
Error_Handler();
|
||||||
{
|
}
|
||||||
|
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
}
|
||||||
|
|
||||||
/* GPIO Ports Clock Enable */
|
/** Configure pins as
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
* Analog
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
* Input
|
||||||
|
* Output
|
||||||
/*Configure GPIO pin Output Level */
|
* EVENT_OUT
|
||||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);
|
* EXTI
|
||||||
|
*/
|
||||||
/*Configure GPIO pins : PA6 PA7 */
|
static void MX_GPIO_Init(void)
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
|
{
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
/* GPIO Ports Clock Enable */
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
}
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
/*Configure GPIO pin Output Level */
|
||||||
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);
|
||||||
{
|
|
||||||
char n = 0;
|
/*Configure GPIO pins : PA6 PA7 */
|
||||||
char UART_Aux[32];
|
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
if (huart->Instance == USART1) {
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
if (UART1_Data != '\n') {
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
UART_Buffer[i] = UART1_Data;
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
i++;
|
|
||||||
} else {
|
}
|
||||||
|
|
||||||
n = sprintf(UART_Aux, "%s\r\n", UART_Buffer);
|
/* USER CODE BEGIN 4 */
|
||||||
|
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
|
||||||
HAL_UART_Transmit(&huart1, (uint8_t*) &UART_Aux, n, 1000);
|
{
|
||||||
|
char n = 0;
|
||||||
|
char UART_Aux[32];
|
||||||
// limpa o '\r'
|
|
||||||
UART_Buffer[i-1] = 0;
|
if (huart->Instance == USART1) {
|
||||||
snprintf(text, 32, "%s", UART_Buffer);
|
if (UART1_Data != '\n') {
|
||||||
|
UART_Buffer[i] = UART1_Data;
|
||||||
i = 0;
|
i++;
|
||||||
}
|
} else {
|
||||||
HAL_UART_Receive_IT(&huart1, (uint8_t*) &UART1_Data, 1);
|
|
||||||
}
|
n = sprintf(UART_Aux, "%s\r\n", UART_Buffer);
|
||||||
}
|
|
||||||
/* USER CODE END 4 */
|
HAL_UART_Transmit(&huart1, (uint8_t*) &UART_Aux, n, 1000);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function is executed in case of error occurrence.
|
// limpa o '\r'
|
||||||
* @param None
|
UART_Buffer[i-1] = 0;
|
||||||
* @retval None
|
snprintf(text, 32, "%s", UART_Buffer);
|
||||||
*/
|
|
||||||
void Error_Handler(void)
|
i = 0;
|
||||||
{
|
}
|
||||||
/* USER CODE BEGIN Error_Handler */
|
HAL_UART_Receive_IT(&huart1, (uint8_t*) &UART1_Data, 1);
|
||||||
/* User can add his own implementation to report the HAL error return state */
|
}
|
||||||
while(1)
|
}
|
||||||
{
|
/* USER CODE END 4 */
|
||||||
}
|
|
||||||
/* USER CODE END Error_Handler */
|
/**
|
||||||
}
|
* @brief This function is executed in case of error occurrence.
|
||||||
|
* @param None
|
||||||
#ifdef USE_FULL_ASSERT
|
* @retval None
|
||||||
|
*/
|
||||||
/**
|
void Error_Handler(void)
|
||||||
* @brief Reports the name of the source file and the source line number
|
{
|
||||||
* where the assert_param error has occurred.
|
/* USER CODE BEGIN Error_Handler */
|
||||||
* @param file: pointer to the source file name
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
* @param line: assert_param error line source number
|
while(1)
|
||||||
* @retval None
|
{
|
||||||
*/
|
}
|
||||||
void assert_failed(uint8_t* file, uint32_t line)
|
/* USER CODE END Error_Handler */
|
||||||
{
|
}
|
||||||
/* USER CODE BEGIN 6 */
|
|
||||||
/* User can add his own implementation to report the file name and line number,
|
#ifdef USE_FULL_ASSERT
|
||||||
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
||||||
/* USER CODE END 6 */
|
/**
|
||||||
|
* @brief Reports the name of the source file and the source line number
|
||||||
}
|
* where the assert_param error has occurred.
|
||||||
|
* @param file: pointer to the source file name
|
||||||
#endif
|
* @param line: assert_param error line source number
|
||||||
|
* @retval None
|
||||||
/**
|
*/
|
||||||
* @}
|
void assert_failed(uint8_t* file, uint32_t line)
|
||||||
*/
|
{
|
||||||
|
/* USER CODE BEGIN 6 */
|
||||||
/**
|
/* User can add his own implementation to report the file name and line number,
|
||||||
* @}
|
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
||||||
*/
|
/* USER CODE END 6 */
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|
345
Src/ssd1306.c
345
Src/ssd1306.c
|
@ -1,213 +1,246 @@
|
||||||
#include"ssd1306.h"
|
#include"ssd1306.h"
|
||||||
|
|
||||||
// Databuffer voor het scherm
|
// Databuffer voor het scherm
|
||||||
static uint8_t SSD1306_Buffer[SSD1306_WIDTH * SSD1306_HEIGHT / 8];
|
//static uint8_t SSD1306_Buffer[SSD1306_WIDTH * SSD1306_HEIGHT / 8];
|
||||||
|
static uint8_t SSD1306_Buffer[SSD1306_HEIGHT * SSD1306_WIDTH / 8];
|
||||||
|
|
||||||
// Een scherm-object om lokaal in te werken
|
// Een scherm-object om lokaal in te werken
|
||||||
static SSD1306_t SSD1306;
|
static SSD1306_t SSD1306;
|
||||||
|
|
||||||
|
void startscrollright(uint8_t start, uint8_t stop){
|
||||||
|
ssd1306_WriteCommand(SSD1306_RIGHT_HORIZONTAL_SCROLL);
|
||||||
|
ssd1306_WriteCommand(0X00);
|
||||||
|
ssd1306_WriteCommand(start);
|
||||||
|
ssd1306_WriteCommand(0X00);
|
||||||
|
ssd1306_WriteCommand(stop);
|
||||||
|
ssd1306_WriteCommand(0X00);
|
||||||
|
ssd1306_WriteCommand(0XFF);
|
||||||
|
ssd1306_WriteCommand(SSD1306_ACTIVATE_SCROLL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ssd1306_Scroll()
|
||||||
|
{
|
||||||
|
static uint32_t end = SSD1306_WIDTH * 8;
|
||||||
|
uint8_t bit_antigo = 0;
|
||||||
|
|
||||||
|
for(uint32_t addr = 0; addr < end; addr++) {
|
||||||
|
if (addr > 0x79) {
|
||||||
|
bit_antigo = SSD1306_Buffer[addr] & 0x01;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSD1306_Buffer[addr] >>= 1;
|
||||||
|
bit_antigo <<= 7;
|
||||||
|
SSD1306_Buffer[addr - SSD1306_WIDTH] |= bit_antigo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Een byte sturen naar het commando register
|
// Een byte sturen naar het commando register
|
||||||
// Kan niet gebruikt worden buiten deze file
|
// Kan niet gebruikt worden buiten deze file
|
||||||
//
|
//
|
||||||
void ssd1306_WriteCommand(uint8_t command)
|
void ssd1306_WriteCommand(uint8_t command)
|
||||||
{
|
{
|
||||||
HAL_I2C_Mem_Write(&hi2c1, SSD1306_I2C_ADDR, 0x00,1, &command, 1, 10);
|
HAL_I2C_Mem_Write(&hi2c1, SSD1306_I2C_ADDR, 0x00,1, &command, 1, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Het scherm initialiseren voor gebruik
|
// Het scherm initialiseren voor gebruik
|
||||||
//
|
//
|
||||||
uint8_t ssd1306_Init(void)
|
uint8_t ssd1306_Init(void)
|
||||||
{
|
{
|
||||||
// Even wachten zodat het scherm zeker opgestart is
|
// Even wachten zodat het scherm zeker opgestart is
|
||||||
HAL_Delay(100);
|
HAL_Delay(100);
|
||||||
|
|
||||||
/* Init LCD */
|
ssd1306_WriteCommand(SSD1306_DISPLAYOFF); // 0xAE
|
||||||
ssd1306_WriteCommand(0xAE); //display off
|
ssd1306_WriteCommand(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
|
||||||
ssd1306_WriteCommand(0x20); //Set Memory Addressing Mode
|
ssd1306_WriteCommand(0x80); // the suggested ratio 0x80
|
||||||
ssd1306_WriteCommand(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
|
|
||||||
ssd1306_WriteCommand(0xB0); //Set Page Start Address for Page Addressing Mode,0-7
|
ssd1306_WriteCommand(SSD1306_SETMULTIPLEX); // 0xA8
|
||||||
ssd1306_WriteCommand(0xC8); //Set COM Output Scan Direction
|
ssd1306_WriteCommand(SSD1306_HEIGHT - 1);
|
||||||
ssd1306_WriteCommand(0x00); //---set low column address
|
|
||||||
ssd1306_WriteCommand(0x10); //---set high column address
|
ssd1306_WriteCommand(SSD1306_SETDISPLAYOFFSET); // 0xD3
|
||||||
ssd1306_WriteCommand(0x40); //--set start line address
|
ssd1306_WriteCommand(0x0); // no offset
|
||||||
ssd1306_WriteCommand(0x81); //--set contrast control register
|
ssd1306_WriteCommand(SSD1306_SETSTARTLINE | 0x0); // line #0
|
||||||
ssd1306_WriteCommand(0xFF);
|
ssd1306_WriteCommand(SSD1306_CHARGEPUMP); // 0x8D
|
||||||
ssd1306_WriteCommand(0xA1); //--set segment re-map 0 to 127
|
|
||||||
ssd1306_WriteCommand(0xA6); //--set normal display
|
ssd1306_WriteCommand(0x14);
|
||||||
ssd1306_WriteCommand(0xA8); //--set multiplex ratio(1 to 64)
|
|
||||||
ssd1306_WriteCommand(0x3F); //
|
ssd1306_WriteCommand(SSD1306_MEMORYMODE); // 0x20
|
||||||
ssd1306_WriteCommand(0xA4); //0xa4,Output follows RAM content;0xa5,Output ignores RAM content
|
ssd1306_WriteCommand(0x00); // 0x0 act like ks0108
|
||||||
ssd1306_WriteCommand(0xD3); //-set display offset
|
ssd1306_WriteCommand(SSD1306_SEGREMAP | 0x1);
|
||||||
ssd1306_WriteCommand(0x00); //-not offset
|
ssd1306_WriteCommand(SSD1306_COMSCANDEC);
|
||||||
ssd1306_WriteCommand(0xD5); //--set display clock divide ratio/oscillator frequency
|
|
||||||
ssd1306_WriteCommand(0xF0); //--set divide ratio
|
ssd1306_WriteCommand(SSD1306_SETCOMPINS); // 0xDA
|
||||||
ssd1306_WriteCommand(0xD9); //--set pre-charge period
|
ssd1306_WriteCommand(0x12);
|
||||||
ssd1306_WriteCommand(0x22); //
|
ssd1306_WriteCommand(SSD1306_SETCONTRAST); // 0x81
|
||||||
ssd1306_WriteCommand(0xDA); //--set com pins hardware configuration
|
ssd1306_WriteCommand(0xCF);
|
||||||
ssd1306_WriteCommand(0x12);
|
|
||||||
ssd1306_WriteCommand(0xDB); //--set vcomh
|
ssd1306_WriteCommand(SSD1306_SETPRECHARGE);
|
||||||
ssd1306_WriteCommand(0x20); //0x20,0.77xVcc
|
ssd1306_WriteCommand(0xF1);
|
||||||
ssd1306_WriteCommand(0x8D); //--set DC-DC enable
|
|
||||||
ssd1306_WriteCommand(0x14); //
|
ssd1306_WriteCommand(SSD1306_SETVCOMDETECT); // 0xDB
|
||||||
ssd1306_WriteCommand(0xAF); //--turn on SSD1306 panel
|
ssd1306_WriteCommand(0x40);
|
||||||
|
ssd1306_WriteCommand(SSD1306_DISPLAYALLON_RESUME); // 0xA4
|
||||||
/* Clearen scherm */
|
ssd1306_WriteCommand(SSD1306_NORMALDISPLAY); // 0xA6
|
||||||
ssd1306_Fill(Black);
|
|
||||||
|
ssd1306_WriteCommand(SSD1306_DEACTIVATE_SCROLL);
|
||||||
/* Update screen */
|
|
||||||
ssd1306_UpdateScreen();
|
ssd1306_WriteCommand(SSD1306_DISPLAYON);//--turn on oled panel
|
||||||
|
|
||||||
/* Set default values */
|
/* Clearen scherm */
|
||||||
SSD1306.CurrentX = 0;
|
ssd1306_Fill(Black);
|
||||||
SSD1306.CurrentY = 0;
|
|
||||||
|
/* Update screen */
|
||||||
/* Initialized OK */
|
ssd1306_UpdateScreen();
|
||||||
SSD1306.Initialized = 1;
|
|
||||||
|
/* Set default values */
|
||||||
/* Return OK */
|
SSD1306.CurrentX = 0;
|
||||||
return 1;
|
SSD1306.CurrentY = 0;
|
||||||
|
|
||||||
|
/* Initialized OK */
|
||||||
|
SSD1306.Initialized = 1;
|
||||||
|
|
||||||
|
/* Return OK */
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// We zetten de hele buffer op een bepaalde kleur
|
// We zetten de hele buffer op een bepaalde kleur
|
||||||
// color => de kleur waarin alles moet
|
// color => de kleur waarin alles moet
|
||||||
//
|
//
|
||||||
void ssd1306_Fill(SSD1306_COLOR color)
|
void ssd1306_Fill(SSD1306_COLOR color)
|
||||||
{
|
{
|
||||||
/* Set memory */
|
/* Set memory */
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
for(i = 0; i < sizeof(SSD1306_Buffer); i++)
|
for(i = 0; i < sizeof(SSD1306_Buffer); i++)
|
||||||
{
|
{
|
||||||
SSD1306_Buffer[i] = (color == Black) ? 0x00 : 0xFF;
|
SSD1306_Buffer[i] = (color == Black) ? 0x00 : 0xFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Alle weizigingen in de buffer naar het scherm sturen
|
// Alle weizigingen in de buffer naar het scherm sturen
|
||||||
//
|
//
|
||||||
void ssd1306_UpdateScreen(void)
|
void ssd1306_UpdateScreen(void)
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
ssd1306_WriteCommand(0xB0 + i);
|
ssd1306_WriteCommand(0xB0 + i);
|
||||||
ssd1306_WriteCommand(0x00);
|
ssd1306_WriteCommand(0x00);
|
||||||
ssd1306_WriteCommand(0x10);
|
ssd1306_WriteCommand(0x10);
|
||||||
|
|
||||||
// We schrijven alles map per map weg
|
// We schrijven alles map per map weg
|
||||||
HAL_I2C_Mem_Write(&hi2c1,SSD1306_I2C_ADDR,0x40,1,&SSD1306_Buffer[SSD1306_WIDTH * i],SSD1306_WIDTH,100);
|
HAL_I2C_Mem_Write(&hi2c1,SSD1306_I2C_ADDR,0x40,1,&SSD1306_Buffer[SSD1306_WIDTH * i],SSD1306_WIDTH,100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// 1 pixel op het scherm tekenen
|
// 1 pixel op het scherm tekenen
|
||||||
// X => X coordinaat
|
// X => X coordinaat
|
||||||
// Y => Y coordinaat
|
// Y => Y coordinaat
|
||||||
// color => kleur die pixel moet krijgen
|
// color => kleur die pixel moet krijgen
|
||||||
//
|
//
|
||||||
void ssd1306_DrawPixel(uint8_t x, uint8_t y, SSD1306_COLOR color)
|
void ssd1306_DrawPixel(uint8_t x, uint8_t y, SSD1306_COLOR color)
|
||||||
{
|
{
|
||||||
if (x >= SSD1306_WIDTH || y >= SSD1306_HEIGHT)
|
if (x >= SSD1306_WIDTH || y >= SSD1306_HEIGHT)
|
||||||
{
|
{
|
||||||
// We gaan niet buiten het scherm schrijven
|
// We gaan niet buiten het scherm schrijven
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kijken of de pixel geinverteerd moet worden
|
// Kijken of de pixel geinverteerd moet worden
|
||||||
if (SSD1306.Inverted)
|
if (SSD1306.Inverted)
|
||||||
{
|
{
|
||||||
color = (SSD1306_COLOR)!color;
|
color = (SSD1306_COLOR)!color;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We zetten de juiste kleur voor de pixel
|
// We zetten de juiste kleur voor de pixel
|
||||||
if (color == White)
|
if (color == White)
|
||||||
{
|
{
|
||||||
SSD1306_Buffer[x + (y / 8) * SSD1306_WIDTH] |= 1 << (y % 8);
|
SSD1306_Buffer[x + (y / 8) * SSD1306_WIDTH] |= 1 << (y % 8);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SSD1306_Buffer[x + (y / 8) * SSD1306_WIDTH] &= ~(1 << (y % 8));
|
SSD1306_Buffer[x + (y / 8) * SSD1306_WIDTH] &= ~(1 << (y % 8));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// We willen 1 char naar het scherm sturen
|
// We willen 1 char naar het scherm sturen
|
||||||
// ch => char om weg te schrijven
|
// ch => char om weg te schrijven
|
||||||
// Font => Font waarmee we gaan schrijven
|
// Font => Font waarmee we gaan schrijven
|
||||||
// color => Black or White
|
// color => Black or White
|
||||||
//
|
//
|
||||||
char ssd1306_WriteChar(char ch, FontDef Font, SSD1306_COLOR color)
|
char ssd1306_WriteChar(char ch, FontDef Font, SSD1306_COLOR color)
|
||||||
{
|
{
|
||||||
uint32_t i, b, j;
|
uint32_t i, b, j;
|
||||||
|
|
||||||
// Kijken of er nog plaats is op deze lijn
|
// Kijken of er nog plaats is op deze lijn
|
||||||
if (SSD1306_WIDTH <= (SSD1306.CurrentX + Font.FontWidth) ||
|
if (SSD1306_WIDTH <= (SSD1306.CurrentX + Font.FontWidth) ||
|
||||||
SSD1306_HEIGHT <= (SSD1306.CurrentY + Font.FontHeight))
|
SSD1306_HEIGHT <= (SSD1306.CurrentY + Font.FontHeight))
|
||||||
{
|
{
|
||||||
// Er is geen plaats meer
|
// Er is geen plaats meer
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We gaan door het font
|
// We gaan door het font
|
||||||
for (i = 0; i < Font.FontHeight; i++)
|
for (i = 0; i < Font.FontHeight; i++)
|
||||||
{
|
{
|
||||||
b = Font.data[(ch - 32) * Font.FontHeight + i];
|
b = Font.data[(ch - 32) * Font.FontHeight + i];
|
||||||
for (j = 0; j < Font.FontWidth; j++)
|
for (j = 0; j < Font.FontWidth; j++)
|
||||||
{
|
{
|
||||||
if ((b << j) & 0x8000)
|
if ((b << j) & 0x8000)
|
||||||
{
|
{
|
||||||
ssd1306_DrawPixel(SSD1306.CurrentX + j, (SSD1306.CurrentY + i), (SSD1306_COLOR) color);
|
ssd1306_DrawPixel(SSD1306.CurrentX + j, (SSD1306.CurrentY + i), (SSD1306_COLOR) color);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ssd1306_DrawPixel(SSD1306.CurrentX + j, (SSD1306.CurrentY + i), (SSD1306_COLOR)!color);
|
ssd1306_DrawPixel(SSD1306.CurrentX + j, (SSD1306.CurrentY + i), (SSD1306_COLOR)!color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// De huidige positie is nu verplaatst
|
// De huidige positie is nu verplaatst
|
||||||
SSD1306.CurrentX += Font.FontWidth;
|
SSD1306.CurrentX += Font.FontWidth;
|
||||||
|
|
||||||
// We geven het geschreven char terug voor validatie
|
// We geven het geschreven char terug voor validatie
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Functie voor het wegschrijven van een hele string
|
// Functie voor het wegschrijven van een hele string
|
||||||
// str => string om op het scherm te schrijven
|
// str => string om op het scherm te schrijven
|
||||||
// Font => Het font dat gebruikt moet worden
|
// Font => Het font dat gebruikt moet worden
|
||||||
// color => Black or White
|
// color => Black or White
|
||||||
//
|
//
|
||||||
char ssd1306_WriteString(char* str, FontDef Font, SSD1306_COLOR color)
|
char ssd1306_WriteString(char* str, FontDef Font, SSD1306_COLOR color)
|
||||||
{
|
{
|
||||||
// We schrijven alle char tot een nulbyte
|
// We schrijven alle char tot een nulbyte
|
||||||
while (*str)
|
while (*str)
|
||||||
{
|
{
|
||||||
if (ssd1306_WriteChar(*str, Font, color) != *str)
|
if (ssd1306_WriteChar(*str, Font, color) != *str)
|
||||||
{
|
{
|
||||||
// Het karakter is niet juist weggeschreven
|
// Het karakter is niet juist weggeschreven
|
||||||
return *str;
|
return *str;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Volgende char
|
// Volgende char
|
||||||
str++;
|
str++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alles gelukt, we sturen dus 0 terug
|
// Alles gelukt, we sturen dus 0 terug
|
||||||
return *str;
|
return *str;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Zet de cursor op een coordinaat
|
// Zet de cursor op een coordinaat
|
||||||
//
|
//
|
||||||
void ssd1306_SetCursor(uint8_t x, uint8_t y)
|
void ssd1306_SetCursor(uint8_t x, uint8_t y)
|
||||||
{
|
{
|
||||||
/* Set write pointers */
|
/* Set write pointers */
|
||||||
SSD1306.CurrentX = x;
|
SSD1306.CurrentX = x;
|
||||||
SSD1306.CurrentY = y;
|
SSD1306.CurrentY = y;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue