Cleanup I2C and drivers
This commit is contained in:
@@ -12,8 +12,8 @@
|
||||
#include "Translation.h"
|
||||
|
||||
#define FONT_12_WIDTH 12
|
||||
// FONTS ARE NO LONGER HERE, MOVED TO PYTHON AUTO GEN
|
||||
|
||||
// THE MAIN FONTS ARE NO LONGER HERE, MOVED TO PYTHON AUTO GEN
|
||||
// THESE ARE ONLY THE SYMBOL FONTS
|
||||
|
||||
const uint8_t ExtraFontChars[] = {
|
||||
//width = 12
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#ifndef FRTOSI2C_HPP_
|
||||
#define FRTOSI2C_HPP_
|
||||
#include "stm32f1xx_hal.h"
|
||||
|
||||
#include "cmsis_os.h"
|
||||
|
||||
/*
|
||||
@@ -21,8 +21,7 @@
|
||||
class FRToSI2C {
|
||||
public:
|
||||
|
||||
static void init(I2C_HandleTypeDef *i2chandle) {
|
||||
i2c = i2chandle;
|
||||
static void init() {
|
||||
I2CSemaphore = nullptr;
|
||||
}
|
||||
|
||||
@@ -34,9 +33,9 @@ public:
|
||||
static void CpltCallback(); //Normal Tx Callback
|
||||
|
||||
static bool Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
||||
uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
|
||||
uint8_t *pData, uint16_t Size);
|
||||
static void Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
||||
uint16_t MemAddSize, uint8_t *pData, uint16_t Size);
|
||||
uint8_t *pData, uint16_t Size);
|
||||
//Returns true if device ACK's being addressed
|
||||
static bool probe(uint16_t DevAddress);
|
||||
|
||||
@@ -45,8 +44,7 @@ public:
|
||||
static uint8_t I2C_RegisterRead(uint8_t address, uint8_t reg);
|
||||
|
||||
private:
|
||||
static I2C_HandleTypeDef *i2c;
|
||||
static void I2C1_ClearBusyFlagErratum();
|
||||
static void I2C_Unstick();
|
||||
static SemaphoreHandle_t I2CSemaphore;
|
||||
static StaticSemaphore_t xSemaphoreBuffer;
|
||||
};
|
||||
|
||||
@@ -38,7 +38,7 @@ void LIS2DH12::initalize() {
|
||||
void LIS2DH12::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
std::array<int16_t, 3> sensorData;
|
||||
|
||||
FRToSI2C::Mem_Read(LIS2DH_I2C_ADDRESS, 0xA8, I2C_MEMADD_SIZE_8BIT,
|
||||
FRToSI2C::Mem_Read(LIS2DH_I2C_ADDRESS, 0xA8,
|
||||
reinterpret_cast<uint8_t*>(sensorData.begin()),
|
||||
sensorData.size() * sizeof(int16_t));
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#ifndef LIS2DH12_HPP_
|
||||
#define LIS2DH12_HPP_
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "I2C_Wrapper.hpp"
|
||||
#include "LIS2DH12_defines.hpp"
|
||||
#include "BSP.h"
|
||||
|
||||
@@ -42,7 +42,7 @@ void MMA8652FC::initalize() {
|
||||
i2c_registers[index].val);
|
||||
index++;
|
||||
|
||||
HAL_Delay(2); // ~1ms delay
|
||||
delay_ms(2); // ~1ms delay
|
||||
|
||||
while (index < (sizeof(i2c_registers) / sizeof(i2c_registers[0]))) {
|
||||
FRToSI2C::I2C_RegisterWrite(MMA8652FC_I2C_ADDRESS,
|
||||
@@ -72,7 +72,7 @@ void MMA8652FC::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
||||
std::array<int16_t, 3> sensorData;
|
||||
|
||||
FRToSI2C::Mem_Read(MMA8652FC_I2C_ADDRESS, OUT_X_MSB_REG,
|
||||
I2C_MEMADD_SIZE_8BIT, reinterpret_cast<uint8_t*>(sensorData.begin()),
|
||||
reinterpret_cast<uint8_t*>(sensorData.begin()),
|
||||
sensorData.size() * sizeof(int16_t));
|
||||
|
||||
x = static_cast<int16_t>(__builtin_bswap16(
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#ifndef MMA8652FC_HPP_
|
||||
#define MMA8652FC_HPP_
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include "MMA8652FC_defines.h"
|
||||
#include "I2C_Wrapper.hpp"
|
||||
#include "BSP.h"
|
||||
|
||||
@@ -63,7 +63,6 @@ uint8_t OLED_Setup_Array[] = {
|
||||
const uint8_t REFRESH_COMMANDS[17] = { 0x80, 0xAF, 0x80, 0x21, 0x80, 0x20, 0x80,
|
||||
0x7F, 0x80, 0xC0, 0x80, 0x22, 0x80, 0x00, 0x80, 0x01, 0x40 };
|
||||
|
||||
|
||||
/*
|
||||
* Animation timing function that follows a bezier curve.
|
||||
* @param t A given percentage value [0..<100]
|
||||
@@ -144,10 +143,10 @@ void OLED::drawScrollIndicator(uint8_t y, uint8_t height) {
|
||||
uint16_t whole;
|
||||
uint8_t strips[2];
|
||||
} column;
|
||||
|
||||
|
||||
column.whole = (1 << height) - 1;
|
||||
column.whole <<= y;
|
||||
|
||||
|
||||
// Draw a one pixel wide bar to the left with a single pixel as
|
||||
// the scroll indicator.
|
||||
fillArea(OLED_WIDTH - 1, 0, 1, 8, column.strips[0]);
|
||||
@@ -191,11 +190,14 @@ void OLED::transitionSecondaryFramebuffer(bool forwardNavigation) {
|
||||
|
||||
offset = progress;
|
||||
|
||||
memmove(&firstStripPtr[oldStart], &firstStripPtr[oldPrevious], OLED_WIDTH - progress);
|
||||
memmove(&secondStripPtr[oldStart], &secondStripPtr[oldPrevious], OLED_WIDTH - progress);
|
||||
memmove(&firstStripPtr[oldStart], &firstStripPtr[oldPrevious],
|
||||
OLED_WIDTH - progress);
|
||||
memmove(&secondStripPtr[oldStart], &secondStripPtr[oldPrevious],
|
||||
OLED_WIDTH - progress);
|
||||
|
||||
memmove(&firstStripPtr[newStart], &firstBackStripPtr[newEnd], progress);
|
||||
memmove(&secondStripPtr[newStart], &secondBackStripPtr[newEnd], progress);
|
||||
memmove(&secondStripPtr[newStart], &secondBackStripPtr[newEnd],
|
||||
progress);
|
||||
|
||||
refresh();
|
||||
osDelay(40);
|
||||
@@ -271,7 +273,7 @@ uint8_t OLED::getFont() {
|
||||
inline void stripLeaderZeros(char *buffer, uint8_t places) {
|
||||
//Removing the leading zero's by swapping them to SymbolSpace
|
||||
// Stop 1 short so that we dont blank entire number if its zero
|
||||
for (int i = 0; i < (places-1); i++) {
|
||||
for (int i = 0; i < (places - 1); i++) {
|
||||
if (buffer[i] == 2) {
|
||||
buffer[i] = SymbolSpace[0];
|
||||
} else {
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#ifndef OLED_HPP_
|
||||
#define OLED_HPP_
|
||||
#include <BSP.h>
|
||||
#include "stm32f1xx_hal.h"
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "I2C_Wrapper.hpp"
|
||||
@@ -27,12 +26,11 @@ extern "C" {
|
||||
#define OLED_HEIGHT 16
|
||||
#define FRAMEBUFFER_START 17
|
||||
|
||||
class OLED {
|
||||
class OLED {
|
||||
public:
|
||||
|
||||
enum DisplayState : bool {
|
||||
OFF = false,
|
||||
ON = true
|
||||
OFF = false, ON = true
|
||||
};
|
||||
|
||||
static void initialize(); // Startup the I2C coms (brings screen out of reset etc)
|
||||
@@ -40,7 +38,7 @@ public:
|
||||
// Draw the buffer out to the LCD using the DMA Channel
|
||||
static void refresh() {
|
||||
FRToSI2C::Transmit( DEVICEADDR_OLED, screenBuffer,
|
||||
FRAMEBUFFER_START + (OLED_WIDTH * 2));
|
||||
FRAMEBUFFER_START + (OLED_WIDTH * 2));
|
||||
//DMA tx time is ~ 20mS Ensure after calling this you delay for at least 25ms
|
||||
//or we need to goto double buffering
|
||||
}
|
||||
@@ -49,16 +47,16 @@ public:
|
||||
displayState = state;
|
||||
screenBuffer[1] = (state == ON) ? 0xAF : 0xAE;
|
||||
}
|
||||
|
||||
|
||||
static void setRotation(bool leftHanded); // Set the rotation for the screen
|
||||
// Get the current rotation of the LCD
|
||||
static bool getRotation() {
|
||||
static bool getRotation() {
|
||||
return inLeftHandedMode;
|
||||
}
|
||||
static int16_t getCursorX() {
|
||||
return cursor_x;
|
||||
}
|
||||
static void print(const char* string);// Draw a string to the current location, with current font
|
||||
static void print(const char *string);// Draw a string to the current location, with current font
|
||||
// Set the cursor location by pixels
|
||||
static void setCursor(int16_t x, int16_t y) {
|
||||
cursor_x = x;
|
||||
@@ -71,11 +69,12 @@ public:
|
||||
}
|
||||
static void setFont(uint8_t fontNumber); // (Future) Set the font that is being used
|
||||
static uint8_t getFont();
|
||||
static void drawImage(const uint8_t* buffer, uint8_t x, uint8_t width) {
|
||||
static void drawImage(const uint8_t *buffer, uint8_t x, uint8_t width) {
|
||||
drawArea(x, 0, width, 16, buffer);
|
||||
}
|
||||
// Draws an image to the buffer, at x offset from top to bottom (fixed height renders)
|
||||
static void printNumber(uint16_t number, uint8_t places,bool noLeaderZeros=true);
|
||||
static void printNumber(uint16_t number, uint8_t places,
|
||||
bool noLeaderZeros = true);
|
||||
// Draws a number at the current cursor location
|
||||
// Clears the buffer
|
||||
static void clearScreen() {
|
||||
@@ -92,9 +91,9 @@ public:
|
||||
static void debugNumber(int32_t val);
|
||||
static void drawSymbol(uint8_t symbolID);//Used for drawing symbols of a predictable width
|
||||
static void drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
|
||||
const uint8_t* ptr); //Draw an area, but y must be aligned on 0/8 offset
|
||||
static void drawAreaSwapped(int16_t x, int8_t y, uint8_t wide, uint8_t height,
|
||||
const uint8_t* ptr); //Draw an area, but y must be aligned on 0/8 offset
|
||||
const uint8_t *ptr); //Draw an area, but y must be aligned on 0/8 offset
|
||||
static void drawAreaSwapped(int16_t x, int8_t y, uint8_t wide,
|
||||
uint8_t height, const uint8_t *ptr); //Draw an area, but y must be aligned on 0/8 offset
|
||||
static void fillArea(int16_t x, int8_t y, uint8_t wide, uint8_t height,
|
||||
const uint8_t value); //Fill an area, but y must be aligned on 0/8 offset
|
||||
static void drawFilledRect(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
|
||||
@@ -106,9 +105,9 @@ public:
|
||||
private:
|
||||
static void drawChar(char c); // Draw a character to a specific location
|
||||
static void setFramebuffer(uint8_t *buffer);
|
||||
static const uint8_t* currentFont;// Pointer to the current font used for rendering to the buffer
|
||||
static uint8_t* firstStripPtr; // Pointers to the strips to allow for buffer having extra content
|
||||
static uint8_t* secondStripPtr; //Pointers to the strips
|
||||
static const uint8_t *currentFont; // Pointer to the current font used for rendering to the buffer
|
||||
static uint8_t *firstStripPtr; // Pointers to the strips to allow for buffer having extra content
|
||||
static uint8_t *secondStripPtr; //Pointers to the strips
|
||||
static bool inLeftHandedMode; // Whether the screen is in left or not (used for offsets in GRAM)
|
||||
static DisplayState displayState;
|
||||
static uint8_t fontWidth, fontHeight;
|
||||
|
||||
Reference in New Issue
Block a user