* Add SDK * fork * massaging makefile * Drop git module * Bring in sdk as its broken Far, Far to much crap to fix with regex now * Remove bl706 * rf_para_flash_t is missing defs * Remove crapton of junk * Remove yet more * Poking I2C * Update peripheral_config.h * Update pinmux_config.h * Update preRTOS.cpp * Update main.hpp * Setup template * Verbose boot * I2C ish * Update I2C_Wrapper.cpp * Update main.cpp * Turn off I2C reading for now * Display running * Roughing out scheduling timer0 * Starting ADC setup * Working scheduling of ADC 🎉 * Format adc headers * Update IRQ.cpp * Buttons working * Slow down I2C * Poking IRQ * Larger stack required * Accel on * Trying to chase down why __libc_init_array isnt working yet * Working c++ * Cleanup * Bump stacks * I2C wake part workaround * Cleanup * Working PWM init * qc draft * Hookup PWM * Stable enough ADC * ADC timing faster + timer without HAL * Silence * Remove boot banner * Tuning in ADC * Wake PID after ADC * Remove unused hal * Draft flash settings * Working settings save & restore * Update to prod model * Cleanup * NTC thermistor * Correct adc gain * Rough tip resistance progress * Scratch out resistance awareness of the tip * better adc settings * Tweaking ADC * ADC tweaking * Make adc range scalable * Update Dockerfile * Update configuration.h * Can read same ADC twice in a row * ADC Setup * Update PIDThread.cpp * Lesser adc backoff * Update USBPD.h * Add device ID * Update BSP_Power.h * Update BSP.cpp * DrawHex dynamicLength * Shorter ID padding * Show validation code * tip measurement * Create access for w0w1 * Expose w0 w1 * Enable debug * crc32 * Device validation * wip starting epr * Logic refactor * Safer PWM Init * PD cleanups * Update bl702_pwm.c * Update power.cpp * Update usb-pd * io * EPR decode * Better gui for showing pd specs * Rough handler for capabilities * EPR * Fix > 25V input * Perform pow step after PPS * Update BSP.cpp * Fix timer output * QC3 * Add tip resistance view * Hold PD negotiation until detection is done for tip res * Get Thermal mass * Tip res =0 protection * Update PIDThread.cpp * Update GUIThread.cpp * Rewrite tip resistance measurement * Update GUIThread.cpp * Fix fallback * Far better tip resistance measurement * Fix QC 0.6V D- * Convert the interpolator to int32 * Correct the NTC lookup * Update BSP.cpp * Update Setup.cpp * . Update configuration #defines More backported functions * Update usb-pd * More missed updates * Refactor BSP Magic BSP -> PinecilV2 Pine64 BSP -> Pinecil Update Makefile * Add Pinecilv2 to CI * Pinecil v2 multi-lang Update push.yml * Update HallSensor.md * Update README.md * Fix wrong prestartcheck default * Fix logo mapping * Update Makefile * Remove unused font block * Style * Style * Remove unused timer funcs * More culling TS80P * Revert "More culling TS80P" This reverts commit2078b89be7. * Revert "Remove unused timer funcs" This reverts commit0c693a89cc. * Make VBus check maskable * Remove DMA half transfer * Drop using brightness and invert icons and go back to text Saves flash space * Refactor settings UI drawing descriptions * Shorten setting function names * Store bin file assets * Fix MHP prestart
128 lines
3.6 KiB
C++
128 lines
3.6 KiB
C++
/*
|
|
* FRToSI2C.cpp
|
|
*
|
|
* Created on: 14Apr.,2018
|
|
* Author: Ralim
|
|
*/
|
|
#include "BSP.h"
|
|
#include "IRQ.h"
|
|
#include "Setup.h"
|
|
extern "C" {
|
|
#include "bflb_platform.h"
|
|
#include "bl702_glb.h"
|
|
#include "bl702_i2c.h"
|
|
}
|
|
#include <I2C_Wrapper.hpp>
|
|
|
|
SemaphoreHandle_t FRToSI2C::I2CSemaphore = nullptr;
|
|
StaticSemaphore_t FRToSI2C::xSemaphoreBuffer;
|
|
#define I2C_TIME_OUT (uint16_t)(12000)
|
|
void FRToSI2C::CpltCallback() {} // Not used
|
|
|
|
bool FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) { return Mem_Write(address, reg, &data, 1); }
|
|
|
|
uint8_t FRToSI2C::I2C_RegisterRead(uint8_t add, uint8_t reg) {
|
|
uint8_t temp = 0;
|
|
Mem_Read(add, reg, &temp, 1);
|
|
return temp;
|
|
}
|
|
|
|
bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t read_address, uint8_t *p_buffer, uint16_t number_of_byte) {
|
|
if (!lock()) {
|
|
return false;
|
|
}
|
|
I2C_Transfer_Cfg i2cCfg = {0, DISABLE, 0, 0, 0, 0};
|
|
BL_Err_Type err = ERROR;
|
|
i2cCfg.slaveAddr = DevAddress >> 1;
|
|
i2cCfg.stopEveryByte = DISABLE;
|
|
i2cCfg.subAddr = read_address;
|
|
i2cCfg.dataSize = number_of_byte;
|
|
i2cCfg.data = p_buffer;
|
|
i2cCfg.subAddrSize = 1; // one byte address
|
|
|
|
err = I2C_MasterReceiveBlocking(I2C0_ID, &i2cCfg);
|
|
bool res = err == SUCCESS;
|
|
if (!res) {
|
|
I2C_Unstick();
|
|
}
|
|
unlock();
|
|
return res;
|
|
}
|
|
|
|
bool FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress, uint8_t *p_buffer, uint16_t number_of_byte) {
|
|
if (!lock()) {
|
|
return false;
|
|
}
|
|
I2C_Transfer_Cfg i2cCfg = {0, DISABLE, 0, 0, 0, 0};
|
|
BL_Err_Type err = ERROR;
|
|
i2cCfg.slaveAddr = DevAddress >> 1;
|
|
i2cCfg.stopEveryByte = DISABLE;
|
|
i2cCfg.subAddr = MemAddress;
|
|
i2cCfg.dataSize = number_of_byte;
|
|
i2cCfg.data = p_buffer;
|
|
i2cCfg.subAddrSize = 1; // one byte address
|
|
|
|
err = I2C_MasterSendBlocking(I2C0_ID, &i2cCfg);
|
|
bool res = err == SUCCESS;
|
|
if (!res) {
|
|
I2C_Unstick();
|
|
}
|
|
unlock();
|
|
return res;
|
|
}
|
|
|
|
bool FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) { return Mem_Write(DevAddress, pData[0], pData + 1, Size - 1); }
|
|
|
|
bool FRToSI2C::probe(uint16_t DevAddress) {
|
|
uint8_t temp[1];
|
|
return Mem_Read(DevAddress, 0x00, temp, sizeof(temp));
|
|
}
|
|
|
|
void FRToSI2C::I2C_Unstick() { unstick_I2C(); }
|
|
|
|
bool FRToSI2C::lock() {
|
|
if (I2CSemaphore == nullptr) {
|
|
return false;
|
|
}
|
|
return xSemaphoreTake(I2CSemaphore, TICKS_SECOND) == pdTRUE;
|
|
}
|
|
|
|
void FRToSI2C::unlock() { xSemaphoreGive(I2CSemaphore); }
|
|
|
|
bool FRToSI2C::writeRegistersBulk(const uint8_t address, const I2C_REG *registers, const uint8_t registersLength) {
|
|
for (int index = 0; index < registersLength; index++) {
|
|
if (!I2C_RegisterWrite(address, registers[index].reg, registers[index].val)) {
|
|
return false;
|
|
}
|
|
if (registers[index].pause_ms) {
|
|
delay_ms(registers[index].pause_ms);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool FRToSI2C::wakePart(uint16_t DevAddress) {
|
|
// wakepart is a special case where only the device address is sent
|
|
|
|
if (!lock()) {
|
|
return false;
|
|
}
|
|
uint8_t temp[1] = {0};
|
|
I2C_Transfer_Cfg i2cCfg = {0, DISABLE, 0, 0, 0, 0};
|
|
BL_Err_Type err = ERROR;
|
|
i2cCfg.slaveAddr = DevAddress >> 1;
|
|
i2cCfg.stopEveryByte = DISABLE;
|
|
i2cCfg.subAddr = 0;
|
|
i2cCfg.dataSize = 1;
|
|
i2cCfg.data = temp;
|
|
i2cCfg.subAddrSize = 0;
|
|
|
|
err = I2C_MasterReceiveBlocking(I2C0_ID, &i2cCfg);
|
|
bool res = err == SUCCESS;
|
|
if (!res) {
|
|
I2C_Unstick();
|
|
}
|
|
unlock();
|
|
return res;
|
|
}
|