-#include "main.h"
-
-#include <stdarg.h>
-#include <stdint.h>
-#include <string.h>
-
-typedef unsigned int uint;
-typedef uint8_t byte;
-typedef uint16_t u16;
-typedef int16_t s16;
-
-void debug_putc(int c)
-{
- while (!LL_USART_IsActiveFlag_TXE(USART2))
- ;
- LL_USART_TransmitData8(USART2, c);
-}
-
-void debug_puts(const char *s)
-{
- while (*s)
- debug_putc(*s++);
-}
-
-enum printf_flags {
- PF_ZERO_PAD = 1,
- PF_SIGNED = 2,
- PF_NEGATIVE = 4,
- PF_UPPERCASE = 8,
- PF_LEFT = 16,
-};
-
-static void printf_string(const char *s, uint width, uint flags)
-{
- uint len = strlen(s);
- uint pad = (len < width) ? width - len : 0;
- char pad_char = (flags & PF_ZERO_PAD) ? '0' : ' ';
-
- if (flags & PF_LEFT)
- debug_puts(s);
- while (pad--)
- debug_putc(pad_char);
- if (!(flags & PF_LEFT))
- debug_puts(s);
-}
-
-static void printf_number(uint i, uint width, uint flags, uint base)
-{
- char buf[16];
- char *w = buf + sizeof(buf);
-
- if (flags & PF_SIGNED)
- {
- if ((int) i < 0)
- {
- i = - (int) i;
- flags |= PF_NEGATIVE;
- }
- }
-
- *--w = 0;
- do
- {
- uint digit = i % base;
- if (digit < 10)
- *--w = '0' + digit;
- else
- *--w = ((flags & PF_UPPERCASE) ? 'A' : 'a') + digit - 10;
- i /= base;
- }
- while (i);
-
- if (flags & PF_NEGATIVE)
- *--w = '-';
-
- printf_string(w, width, flags);
-}
-
-void debug_printf(const char *fmt, ...)
-{
- va_list args;
- va_start(args, fmt);
-
- while (*fmt)
- {
- int c = *fmt++;
- if (c != '%')
- {
- debug_putc(c);
- continue;
- }
-
- uint width = 0;
- uint flags = 0;
-
- if (*fmt == '-')
- {
- fmt++;
- flags |= PF_LEFT;
- }
-
- if (*fmt == '0')
- {
- fmt++;
- flags |= PF_ZERO_PAD;
- }
-
- while (*fmt >= '0' && *fmt <= '9')
- width = 10*width + *fmt++ - '0';
-
- c = *fmt++;
- switch (c)
- {
- case 'd':
- printf_number(va_arg(args, int), width, flags | PF_SIGNED, 10);
- break;
- case 'u':
- printf_number(va_arg(args, int), width, flags, 10);
- break;
- case 'X':
- flags |= PF_UPPERCASE;
- // fall-thru
- case 'x':
- printf_number(va_arg(args, int), width, flags, 16);
- break;
- case 's':
- printf_string(va_arg(args, char *), width, flags);
- break;
- default:
- debug_putc(c);
- continue;
- }
- }
-
- va_end(args);
-}
-
-#if 0
-
-static uint bmp_read(uint reg, uint bytes)
-{
- LL_I2C_ClearFlag_STOP(I2C1);
- LL_I2C_ClearFlag_BERR(I2C1);
- LL_I2C_HandleTransfer(I2C1, 0xee, LL_I2C_ADDRSLAVE_7BIT, 1, LL_I2C_MODE_SOFTEND, LL_I2C_GENERATE_START_WRITE);
- while (!LL_I2C_IsActiveFlag_TXE(I2C1))
- ;
- LL_I2C_TransmitData8(I2C1, reg);
- while (!LL_I2C_IsActiveFlag_TC(I2C1))
- ;
- LL_I2C_HandleTransfer(I2C1, 0xef, LL_I2C_ADDRSLAVE_7BIT, bytes, LL_I2C_MODE_AUTOEND, LL_I2C_GENERATE_RESTART_7BIT_READ);
-
- uint d = 0;
- for (uint i=0; i<bytes; i++)
- {
- while (!LL_I2C_IsActiveFlag_RXNE(I2C1))
- ;
- d = (d << 8) | LL_I2C_ReceiveData8(I2C1);
- }
-
- return d;
-}
-
-static uint bmp_measure(uint type, uint bytes)
-{
- LL_I2C_HandleTransfer(I2C1, 0xee, LL_I2C_ADDRSLAVE_7BIT, 2, LL_I2C_MODE_AUTOEND, LL_I2C_GENERATE_START_WRITE);
- while (!LL_I2C_IsActiveFlag_TXE(I2C1))
- ;
- LL_I2C_TransmitData8(I2C1, 0xf4);
- while (!LL_I2C_IsActiveFlag_TXE(I2C1))
- ;
- LL_I2C_TransmitData8(I2C1, type);
- while (!LL_I2C_IsActiveFlag_STOP(I2C1))
- ;
-
- while (!LL_GPIO_IsInputPinSet(BMP_DONE_GPIO_Port, BMP_DONE_Pin))
- ;
-
- return bmp_read(0xf6, bytes);
-}
-
-// Formulae from BMP085 specs
-void bmp_recalc(uint UT, uint UP, uint oss, u16 cc[11], int *tt, int *pp)
-{
- s16 AC1 = cc[0];
- s16 AC2 = cc[1];
- s16 AC3 = cc[2];
- u16 AC4 = cc[3];
- u16 AC5 = cc[4];
- u16 AC6 = cc[5];
- s16 B1 = cc[6];
- s16 B2 = cc[7];
- s16 MB = cc[8];
- s16 MC = cc[9];
- s16 MD = cc[10];
- UP >>= (8-oss);
-
- int X1 = (UT-AC6)*AC5 / (1<<15);
- int X2 = MC*(1<<11) / (X1+MD);
- int B5 = X1 + X2;
- int T = (B5+8) / (1<<4);
- *tt = T;
-
- int B6 = B5 - 4000;
- X1 = (B2*(B6*B6/(1<<12))) / (1<<11);
- X2 = AC2 * B6 / (1<<11);
- int X3 = X1 + X2;
- int B3 = (((AC1*4 + X3) << oss) + 2) / 4;
- X1 = AC3 * B6 / (1<<13);
- X2 = (B1*(B6*B6/(1<<12))) / (1<<16);
- X3 = ((X1+X2) + 2) / (1<<2);
- uint B4 = (uint)(AC4 * (X3 + 32768)) / (1U<<15);
- uint B7 = (uint)(UP-B3) * (uint)(50000>>oss);
- int p;
- if (B7 < 0x80000000)
- p = (B7*2) / B4;
- else
- p = B7 / B4 * 2;
- X1 = (p/(1<<8)) * (p/(1<<8));
- X1 = (X1*3038) / (1<<16);
- X2 = (-7357*p) / (1<<16);
- p = p + (X1 + X2 + 3791) / (1<<4);
- *pp = p;
-}
-
-void run_test(void)
-{
- for (;;)
- {
- LL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
-
- debug_puts("Constants:");
- u16 cc[11];
- for (uint i=0; i<11; i++)
- {
- cc[i] = bmp_read(0xaa + 2*i, 2);
- debug_printf(" %04x", cc[i]);
- }
- debug_puts("\r\n");
-
- uint raw_temp = bmp_measure(0x2e, 2);
- debug_printf("Raw temperature: %04x\r\n", raw_temp);
-
- uint oss = 3; // Over-sampling setting
- uint raw_press = bmp_measure(0xf4 | (oss<<6), 3);
- debug_printf("Raw pressure: %06x\r\n", raw_press);
-
- int temp, press;
- bmp_recalc(raw_temp, raw_press, oss, cc, &temp, &press);
- debug_printf("Temperature: %d ddegC\r\n", temp);
- debug_printf("Pressure: %d Pa\r\n", press);
-
- LL_mDelay(1000);
- }
-}
-
-#else
-
-static const byte Gentium23x32[] = {
- 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x1F, 0x00, 0x80, 0xFF, 0xFF, 0x00, 0xE0, 0xFF, 0xFF, 0x03, 0xF0, 0xFF, 0xFF, 0x0F, 0xF8, 0xFF, 0xFF, 0x1F, 0xFC, 0xFF, 0xFF, 0x3F, 0xFE, 0x01, 0xE0, 0x3F, 0x3E, 0x00, 0x00, 0x7F, 0x1F, 0x00, 0x00, 0x7C, 0x0F, 0x00, 0x00, 0x78, 0x0F, 0x00, 0x00, 0x78, 0x1F, 0x00, 0x00, 0x78, 0x3F, 0x00, 0x00, 0x78, 0x7F, 0x00, 0x00, 0x3E, 0xFE, 0x07, 0xC0, 0x3F, 0xFE, 0xFF, 0xFF, 0x1F, 0xFC, 0xFF, 0xFF, 0x0F, 0xF8, 0xFF, 0xFF, 0x07, 0xE0, 0xFF, 0xFF, 0x03, 0x80, 0xFF, 0xFF, 0x00, 0x00, 0xFC, 0x0F, 0x00, // Code for char 0
- 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x70, 0x78, 0x00, 0x00, 0x70, 0x78, 0x00, 0x00, 0x78, 0x78, 0x00, 0x00, 0x78, 0x7C, 0x00, 0x00, 0x78, 0x3C, 0x00, 0x00, 0x78, 0xFE, 0xFF, 0xFF, 0x7F, 0xFE, 0xFF, 0xFF, 0x7F, 0xFE, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F, 0xFE, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, // Code for char 1
- 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x80, 0x01, 0x00, 0x78, 0xE0, 0x03, 0x00, 0x7C, 0xF0, 0x03, 0x00, 0x7E, 0xF8, 0x03, 0x80, 0x7F, 0xFC, 0x01, 0xC0, 0x7F, 0xFE, 0x01, 0xE0, 0x7F, 0x3E, 0x00, 0xF0, 0x7F, 0x1E, 0x00, 0xFC, 0x7F, 0x0F, 0x00, 0xFE, 0x79, 0x0F, 0x00, 0xFF, 0x78, 0x0F, 0xC0, 0x7F, 0x78, 0x1F, 0xE0, 0x3F, 0x78, 0x3F, 0xF8, 0x0F, 0x78, 0xFF, 0xFF, 0x07, 0x78, 0xFE, 0xFF, 0x03, 0x78, 0xFE, 0xFF, 0x00, 0x7C, 0xFC, 0x7F, 0x80, 0x7F, 0xF8, 0x1F, 0x80, 0x7F, 0xE0, 0x07, 0x80, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 2
- 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xC0, 0x00, 0x00, 0x1F, 0xF0, 0x01, 0x00, 0x1E, 0xF8, 0x01, 0x00, 0x3E, 0xFC, 0x01, 0x00, 0x3C, 0xFE, 0x00, 0x00, 0x7C, 0xFE, 0x00, 0x00, 0x78, 0x1E, 0xE0, 0x00, 0x78, 0x0F, 0xF0, 0x00, 0x78, 0x0F, 0xF0, 0x00, 0x78, 0x0F, 0xF0, 0x00, 0x78, 0x1F, 0xF8, 0x01, 0x7C, 0x3F, 0xFC, 0x01, 0x7C, 0xFF, 0xFF, 0x07, 0x3F, 0xFE, 0xFF, 0xFF, 0x3F, 0xFE, 0xFF, 0xFF, 0x1F, 0xFC, 0xCF, 0xFF, 0x0F, 0xF8, 0xC7, 0xFF, 0x07, 0xE0, 0x83, 0xFF, 0x03, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 3
- 0x17, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x80, 0x3F, 0x00, 0x00, 0xC0, 0x3F, 0x00, 0x00, 0xF0, 0x3F, 0x00, 0x00, 0xF8, 0x3F, 0x00, 0x00, 0xFE, 0x3D, 0x00, 0x00, 0xFF, 0x3C, 0x70, 0xC0, 0x3F, 0x3C, 0x70, 0xE0, 0x1F, 0x3C, 0x70, 0xF8, 0x07, 0x3C, 0x78, 0xFC, 0x03, 0x3C, 0x78, 0xFE, 0xFF, 0xFF, 0x7F, 0xFE, 0xFF, 0xFF, 0x7F, 0xFE, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0x7F, 0xFE, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0x3C, 0x78, 0x00, 0x00, 0x3C, 0x70, 0x00, 0x00, 0x1C, 0x70, 0x00, 0x00, 0x08, 0x00, // Code for char 4
- 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0xC0, 0x00, 0x1F, 0x00, 0xFE, 0x01, 0x1E, 0xFC, 0xFF, 0x01, 0x3E, 0xFC, 0xFF, 0x00, 0x3C, 0xFC, 0xFF, 0x00, 0x3C, 0xFC, 0x7F, 0x00, 0x78, 0x3C, 0x78, 0x00, 0x78, 0x3C, 0x78, 0x00, 0x78, 0x3C, 0x78, 0x00, 0x78, 0x3C, 0x78, 0x00, 0x78, 0x3C, 0xF8, 0x00, 0x7C, 0x3C, 0xF8, 0x00, 0x7E, 0x3C, 0xF0, 0x03, 0x3F, 0x3C, 0xF0, 0xFF, 0x3F, 0x3C, 0xF0, 0xFF, 0x1F, 0x1E, 0xE0, 0xFF, 0x0F, 0x0F, 0xC0, 0xFF, 0x07, 0x06, 0x80, 0xFF, 0x03, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 5
- 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x7F, 0x00, 0x00, 0xF8, 0xFF, 0x01, 0x00, 0xFE, 0xFF, 0x07, 0x80, 0xFF, 0xFF, 0x0F, 0xC0, 0xFF, 0xFF, 0x1F, 0xE0, 0xFF, 0xFF, 0x3F, 0xF0, 0xFF, 0xC1, 0x3F, 0xF8, 0xF7, 0x00, 0x7E, 0xF8, 0x71, 0x00, 0x7C, 0xFC, 0x78, 0x00, 0x78, 0x7C, 0x78, 0x00, 0x78, 0x3E, 0x78, 0x00, 0x78, 0x1E, 0xF8, 0x00, 0x7C, 0x1E, 0xF8, 0x03, 0x3E, 0x0F, 0xF0, 0xFF, 0x3F, 0x0F, 0xF0, 0xFF, 0x1F, 0x0F, 0xE0, 0xFF, 0x0F, 0x06, 0xE0, 0xFF, 0x07, 0x00, 0x80, 0xFF, 0x03, 0x00, 0x00, 0x7E, 0x00, // Code for char 6
- 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0xF8, 0x01, 0x00, 0x00, 0xFC, 0x01, 0x00, 0x00, 0xFC, 0x01, 0x00, 0x20, 0x7C, 0x00, 0x00, 0x78, 0x3C, 0x00, 0x00, 0x7E, 0x3C, 0x00, 0x80, 0x7F, 0x3C, 0x00, 0xE0, 0x3F, 0x3C, 0x00, 0xF8, 0x3F, 0x3C, 0x00, 0xFE, 0x1F, 0x3C, 0x80, 0xFF, 0x0F, 0x3C, 0xE0, 0xFF, 0x01, 0x3C, 0xF8, 0x7F, 0x00, 0x3C, 0xFE, 0x0F, 0x00, 0xFC, 0xFF, 0x03, 0x00, 0xFC, 0xFF, 0x00, 0x00, 0xFC, 0x1F, 0x00, 0x00, 0xFC, 0x07, 0x00, 0x00, 0xFC, 0x01, 0x00, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, // Code for char 7
- 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x03, 0xC0, 0x07, 0xFC, 0x07, 0xF0, 0x1F, 0xFE, 0x1F, 0xF8, 0x3F, 0xFF, 0x1F, 0xFC, 0xBF, 0xFF, 0x3F, 0xFE, 0xFF, 0xFF, 0x3F, 0xFE, 0xFF, 0x0F, 0x7E, 0x1F, 0xFE, 0x03, 0x7C, 0x0F, 0xFC, 0x01, 0x78, 0x0F, 0xF8, 0x01, 0x78, 0x0F, 0xF8, 0x01, 0x78, 0x0F, 0xF8, 0x03, 0x78, 0x1F, 0xFC, 0x07, 0x7C, 0xFF, 0xFF, 0x0F, 0x3E, 0xFE, 0xFF, 0xFF, 0x3F, 0xFE, 0xDF, 0xFF, 0x1F, 0xFC, 0xCF, 0xFF, 0x0F, 0xF8, 0x87, 0xFF, 0x07, 0xF0, 0x01, 0xFF, 0x03, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 8
- 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0xC0, 0xFF, 0x00, 0x00, 0xF0, 0xFF, 0x01, 0x60, 0xF8, 0xFF, 0x03, 0xE0, 0xFC, 0xFF, 0x07, 0xF0, 0xFC, 0xFF, 0x07, 0xF0, 0x7E, 0xE0, 0x0F, 0xF8, 0x1E, 0x80, 0x0F, 0x78, 0x0F, 0x00, 0x0F, 0x7C, 0x0F, 0x00, 0x0F, 0x7C, 0x0F, 0x00, 0x0F, 0x3E, 0x0F, 0x00, 0x0F, 0x3F, 0x1F, 0x00, 0x87, 0x1F, 0x3F, 0x80, 0xE7, 0x1F, 0xFE, 0xC1, 0xFB, 0x0F, 0xFE, 0xFF, 0xFF, 0x07, 0xFC, 0xFF, 0xFF, 0x03, 0xF8, 0xFF, 0xFF, 0x01, 0xF0, 0xFF, 0x7F, 0x00, 0xC0, 0xFF, 0x1F, 0x00, 0x00, 0xFF, 0x03, 0x00, // Code for char 9
- 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x03, 0xC0, 0x07, 0xF0, 0x07, 0xE0, 0x0F, 0xF8, 0x07, 0xF0, 0x0F, 0xF8, 0x07, 0xF0, 0x0F, 0xF8, 0x07, 0xF0, 0x0F, 0xF8, 0x07, 0xF0, 0x0F, 0xF8, 0x03, 0xF0, 0x07, 0xF0, 0x01, 0xE0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Code for char :
-};
-
-// Based on https://github.com/adafruit/Adafruit_SSD1306
-
-#define SSD1306_SETLOWCOLUMN 0x00
-#define SSD1306_SETHIGHCOLUMN 0x10
-#define SSD1306_MEMORYMODE 0x20
-#define SSD1306_SETSTARTLINE 0x40
-#define SSD1306_SETCONTRAST 0x81
-#define SSD1306_CHARGEPUMP 0x8D
-#define SSD1306_SEGREMAP 0xA0
-#define SSD1306_DISPLAYALLON_RESUME 0xA4
-#define SSD1306_DISPLAYALLON 0xA5
-#define SSD1306_NORMALDISPLAY 0xA6
-#define SSD1306_INVERTDISPLAY 0xA7
-#define SSD1306_SETMULTIPLEX 0xA8
-#define SSD1306_DISPLAYOFF 0xAE
-#define SSD1306_DISPLAYON 0xAF
-#define SSD1306_SETSTARTPAGE 0xB0
-#define SSD1306_COMSCANINC 0xC0
-#define SSD1306_COMSCANDEC 0xC8
-#define SSD1306_SETDISPLAYOFFSET 0xD3
-#define SSD1306_SETCOMPINS 0xDA
-#define SSD1306_SETVCOMDETECT 0xDB
-#define SSD1306_SETDISPLAYCLOCKDIV 0xD5
-#define SSD1306_SETPRECHARGE 0xD9
-#define SSD1306_NOP 0xE3
-
-static const byte display_init_cmds[] = {
- SSD1306_DISPLAYOFF,
- SSD1306_SETDISPLAYCLOCKDIV, 0x80, // the suggested ratio 0x80
- SSD1306_SETMULTIPLEX, 0x1F, // ratio 32
- SSD1306_SETDISPLAYOFFSET,0x0, // no offset
- SSD1306_SETSTARTLINE | 0x0, // line #0
- SSD1306_CHARGEPUMP, 0x14, // internal vcc
- SSD1306_MEMORYMODE, 0x02, // page mode
- SSD1306_SEGREMAP | 0x0, // column 0 mapped to SEG0
- SSD1306_COMSCANINC, // column scan direction not reversed
- SSD1306_SETCOMPINS, 0x02, // sequential COM pins, disable remap
- SSD1306_SETCONTRAST, 0x7F, // contrast level 127
- SSD1306_SETPRECHARGE, 0xF1, // pre-charge period (1, 15)
- SSD1306_SETVCOMDETECT, 0x40, // vcomh regulator level-
- SSD1306_DISPLAYALLON_RESUME,
- SSD1306_NORMALDISPLAY,
- SSD1306_DISPLAYON,
-};
-
-static void display_cmd(byte cmd)
-{
- LL_I2C_ClearFlag_STOP(I2C1);
- LL_I2C_HandleTransfer(I2C1, 0x79, LL_I2C_ADDRSLAVE_7BIT, 2, LL_I2C_MODE_AUTOEND, LL_I2C_GENERATE_START_WRITE);
- while (!LL_I2C_IsActiveFlag_TXE(I2C1))
- ;
- LL_I2C_TransmitData8(I2C1, 0x00); // Will send a command
- while (!LL_I2C_IsActiveFlag_TXE(I2C1))
- ;
- LL_I2C_TransmitData8(I2C1, cmd);
- while (!LL_I2C_IsActiveFlag_STOP(I2C1))
- ;
-}
-
-static void display_data_start(uint cnt)
-{
- LL_I2C_ClearFlag_STOP(I2C1);
- LL_I2C_HandleTransfer(I2C1, 0x79, LL_I2C_ADDRSLAVE_7BIT, cnt + 1, LL_I2C_MODE_AUTOEND, LL_I2C_GENERATE_START_WRITE);
- while (!LL_I2C_IsActiveFlag_TXE(I2C1))
- ;
- LL_I2C_TransmitData8(I2C1, 0x40); // Will send data
-}
-
-static void display_data(byte d)
-{
- while (!LL_I2C_IsActiveFlag_TXE(I2C1))
- ;
- LL_I2C_TransmitData8(I2C1, d);
-}
-
-static void display_data_end(void)
-{
- while (!LL_I2C_IsActiveFlag_STOP(I2C1))
- ;
-}
-
-static void display_init(void)
-{
- for (uint i=0; i < sizeof(display_init_cmds); i++)
- display_cmd(display_init_cmds[i]);
-
- for (uint p=0; p<4; p++)
- {
- display_cmd(SSD1306_SETSTARTPAGE + p);
- display_cmd(SSD1306_SETHIGHCOLUMN);
- display_cmd(SSD1306_SETLOWCOLUMN);
- display_data_start(128);
- for (uint i=0; i<128; i++)
- {
- byte x = 0;
- // x = Gentium23x32[(23*4+1)*(i/23) + 1 + 4*(i%23) + p];
- display_data(x);
- }
- display_data_end();
- }
-}
-
-static void counter(uint cnt)
-{
- byte d[5];
- for (uint i=0; i<5; i++)
- {
- d[4-i] = cnt % 10;
- cnt /= 10;
- }
-
- for (uint p=0; p<4; p++)
- {
- display_cmd(SSD1306_SETSTARTPAGE + p);
- display_cmd(SSD1306_SETHIGHCOLUMN);
- display_cmd(SSD1306_SETLOWCOLUMN);
- display_data_start(5*24);
- for (uint i=0; i<5; i++)
- {
- for (uint j=0; j<23; j++)
- {
- byte x = Gentium23x32[(23*4+1)*d[i] + 1 + 4*j + p];
- display_data(x);
- }
- display_data(0);
- }
- display_data_end();
- }
-}
-
-void run_test(void)
-{
- uint cnt = 0;
-
- debug_puts("Init\r\n");
- display_init();
-
- for (;;)
- {
- LL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
-
- debug_printf("Tick tock: %d\r\n", cnt);
-
- counter(cnt);
-
- LL_mDelay(1000);
- cnt++;
- }
-}
-
-#endif