1
0
forked from me/IronOS

Still testing

This commit is contained in:
Ben V. Brown
2020-07-21 13:39:50 +10:00
parent c70689df7d
commit b6c61cfb52
31 changed files with 674 additions and 557 deletions

View File

@@ -217,6 +217,7 @@ uint8_t getButtonB() {
}
void reboot() {
asm("bkpt");
NVIC_SystemReset();
}

View File

@@ -13,9 +13,11 @@
#define SDA_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET)
#define SDA_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port,SDA2_Pin)==GPIO_PIN_SET?1:0)
#define SCL_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port,SCL2_Pin)==GPIO_PIN_SET?1:0)
#define I2C_DELAY() {for(int xx=0;xx<100;xx++){asm("nop");}}
#define I2C_DELAY() {for(int xx=0;xx<1000;xx++){asm("nop");}}
SemaphoreHandle_t I2CBB::I2CSemaphore = NULL;
StaticSemaphore_t I2CBB::xSemaphoreBuffer;
SemaphoreHandle_t I2CBB::I2CSemaphore2 = NULL;
StaticSemaphore_t I2CBB::xSemaphoreBuffer2;
void I2CBB::init() {
//Set GPIO's to output open drain
GPIO_InitTypeDef GPIO_InitStruct;
@@ -28,8 +30,14 @@ void I2CBB::init() {
SDA_HIGH();
SCL_HIGH();
I2CSemaphore = xSemaphoreCreateBinaryStatic(&xSemaphoreBuffer);
xSemaphoreGive(I2CSemaphore);
I2CSemaphore2 = xSemaphoreCreateBinaryStatic(&xSemaphoreBuffer2);
unlock();
unlock2();
//unstick bus
for (int i = 0; i < 8; i++) {
read_bit();
}
stop();
}
bool I2CBB::probe(uint8_t address) {
@@ -73,8 +81,8 @@ bool I2CBB::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData,
return true;
}
bool I2CBB::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData,
uint16_t Size) {
bool I2CBB::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
const uint8_t *pData, uint16_t Size) {
if (!lock())
return false;
start();
@@ -205,6 +213,7 @@ void I2CBB::start() {
I2C_DELAY();
SCL_LOW();
I2C_DELAY();
SDA_HIGH();
}
void I2CBB::stop() {
@@ -224,6 +233,7 @@ bool I2CBB::send(uint8_t value) {
value <<= 1;
}
SDA_HIGH();
bool ack = read_bit() == 0;
return ack;
}
@@ -237,6 +247,7 @@ uint8_t I2CBB::read(bool ack) {
B |= read_bit();
}
SDA_HIGH();
if (ack)
write_bit(0);
else
@@ -269,7 +280,7 @@ bool I2CBB::lock() {
if (I2CSemaphore == NULL) {
asm("bkpt");
}
bool a = xSemaphoreTake(I2CSemaphore, (TickType_t) 50) == pdTRUE;
bool a = xSemaphoreTake(I2CSemaphore, (TickType_t) 100) == pdTRUE;
if (!a) {
asm("bkpt");
}
@@ -277,13 +288,29 @@ bool I2CBB::lock() {
}
void I2CBB::write_bit(uint8_t val) {
if (val > 0)
if (val) {
SDA_HIGH();
else
} else {
SDA_LOW();
}
I2C_DELAY();
SCL_HIGH();
I2C_DELAY();
SCL_LOW();
}
void I2CBB::unlock2() {
xSemaphoreGive(I2CSemaphore2);
}
bool I2CBB::lock2() {
if (I2CSemaphore2 == NULL) {
asm("bkpt");
}
bool a = xSemaphoreTake(I2CSemaphore2, (TickType_t) 500) == pdTRUE;
if (!a) {
asm("bkpt");
}
return a;
}

View File

@@ -27,14 +27,18 @@ public:
uint8_t *pData, uint16_t Size);
//Implements a register write
static bool Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
uint8_t *pData, uint16_t Size);
const uint8_t *pData, uint16_t Size);
static void Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size);
static void Receive(uint16_t DevAddress, uint8_t *pData, uint16_t Size);
static void TransmitReceive(uint16_t DevAddress, uint8_t *pData_tx,
uint16_t Size_tx, uint8_t *pData_rx, uint16_t Size_rx);
static void unlock2();
static bool lock2();
private:
static SemaphoreHandle_t I2CSemaphore;
static StaticSemaphore_t xSemaphoreBuffer;
static SemaphoreHandle_t I2CSemaphore2;
static StaticSemaphore_t xSemaphoreBuffer2;
static void unlock();
static bool lock();
static void start();

View File

@@ -26,15 +26,7 @@ void power_check() {
uint8_t usb_pd_detect() {
#ifdef MODEL_TS80P
FUSB302_present = fusb302_detect();
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 15, 0);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
InterruptHandler::irqCallback();
return FUSB302_present;
#endif
return false;

View File

@@ -33,9 +33,9 @@ static void MX_ADC2_Init(void);
void Setup_HAL() {
SystemClock_Config();
__HAL_AFIO_REMAP_SWJ_DISABLE()
;
// __HAL_AFIO_REMAP_SWJ_DISABLE()
// ;
__HAL_AFIO_REMAP_SWJ_NOJTAG();
MX_GPIO_Init();
MX_DMA_Init();
MX_I2C1_Init();
@@ -43,7 +43,7 @@ void Setup_HAL() {
MX_ADC2_Init();
MX_TIM3_Init();
MX_TIM2_Init();
MX_IWDG_Init();
// MX_IWDG_Init();
HAL_ADC_Start(&hadc2);
HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t*) ADCReadings, 64); // start DMA of normal readings
HAL_ADCEx_InjectedStart(&hadc1); // enable injected readings
@@ -458,3 +458,8 @@ static void MX_GPIO_Init(void) {
HAL_Delay(30);
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line){
asm("bkpt");
}
#endif

View File

@@ -11,6 +11,7 @@
#if defined(STM32F100xE) || defined(STM32F101xE) || defined(STM32F101xG) || defined(STM32F103xE) || defined(STM32F103xG)
/* #define DATA_IN_ExtSRAM */
#endif /* STM32F100xE || STM32F101xE || STM32F101xG || STM32F103xE || STM32F103xG */
#define LOCAL_BUILD
#ifndef LOCAL_BUILD
#define VECT_TAB_OFFSET 0x00004000U /*!< Vector Table base offset field.
This value must be a multiple of 0x200. */