1
0
forked from me/IronOS

Cleanup model selection

This commit is contained in:
Ben V. Brown
2020-07-25 22:28:38 +10:00
parent f36e78f664
commit e6d1249c91
17 changed files with 165 additions and 106 deletions

View File

@@ -2,7 +2,7 @@
#include "BSP_Power.h"
#include "BSP_QC.h"
#include "Defines.h"
#include "UnitSettings.h"
#include "Model_Config.h"
#include "stdint.h"
/*
* BSP.h -- Board Support

View File

@@ -7,6 +7,7 @@
#include "Pins.h"
#include "main.hpp"
#include "history.hpp"
#include "Model_Config.h"
#include "I2C_Wrapper.hpp"
volatile uint16_t PWMSafetyTimer = 0;
volatile uint8_t pendingPWM = 0;
@@ -16,7 +17,7 @@ history<uint16_t, PID_TIM_HZ> rawTempFilter = { { 0 }, 0, 0 };
void resetWatchdog() {
HAL_IWDG_Refresh(&hiwdg);
}
#ifdef MODEL_TS80P
#ifdef TEMP_NTC
//Lookup table for the NTC
//Stored as ADCReading,Temp in degC
static const uint16_t NTCHandleLookup[] = {
@@ -85,7 +86,7 @@ static const uint16_t NTCHandleLookup[] = {
};
#endif
uint16_t getHandleTemperature() {
#ifdef MODEL_TS80P
#ifdef TEMP_NTC
//TS80P uses 100k NTC resistors instead
//NTCG104EF104FT1X from TDK
//For now not doing interpolation
@@ -97,7 +98,8 @@ uint16_t getHandleTemperature() {
}
}
return 0;
#else
#endif
#ifdef TEMP_TMP36
// We return the current handle temperature in X10 C
// TMP36 in handle, 0.5V offset and then 10mV per deg C (0.75V @ 25C for
// example) STM32 = 4096 count @ 3.3V input -> But We oversample by 32/(2^2) =

View File

@@ -6,7 +6,8 @@
*/
#include "BSP_PD.h"
#include "Model_Config.h"
#ifdef POW_PD
/*
* An array of all of the desired voltages & minimum currents in preferred order
*/
@@ -18,3 +19,4 @@ const uint16_t USB_PD_Desired_Levels[] = {
};
const uint8_t USB_PD_Desired_Levels_Len = 3;
#endif

View File

@@ -0,0 +1,44 @@
/*
* Model_Config.h
*
* Created on: 25 Jul 2020
* Author: Ralim
*/
#ifndef BSP_MINIWARE_MODEL_CONFIG_H_
#define BSP_MINIWARE_MODEL_CONFIG_H_
/*
* Lookup for mapping features <-> Models
*/
#if defined(MODEL_TS100) + defined(MODEL_TS80)+defined(MODEL_TS80P) > 1
#error "Multiple models defined!"
#elif defined(MODEL_TS100) + defined(MODEL_TS80)+ defined(MODEL_TS80P) == 0
#error "No model defined!"
#endif
#ifdef MODEL_TS100
#define ACCEL_MMA
#define ACCEL_LIS
#define TEMP_TMP36
#endif
#ifdef MODEL_TS80
#define ACCEL_LIS
#define POW_QC
#define TEMP_TMP36
#define LIS_ORI_FLIP
#define OLED_FLIP
#endif
#ifdef MODEL_TS80P
#define ACCEL_LIS
#define POW_PD
#define POW_QC
#define TEMP_NTC
#define I2C_SOFT
#define LIS_ORI_FLIP
#define OLED_FLIP
#endif
#endif /* BSP_MINIWARE_MODEL_CONFIG_H_ */

View File

@@ -7,12 +7,7 @@
#ifndef BSP_MINIWARE_PINS_H_
#define BSP_MINIWARE_PINS_H_
#if defined(MODEL_TS100) + defined(MODEL_TS80)+defined(MODEL_TS80P) > 1
#error "Multiple models defined!"
#elif defined(MODEL_TS100) + defined(MODEL_TS80)+ defined(MODEL_TS80P) == 0
#error "No model defined!"
#endif
#include "Model_Config.h"
#ifdef MODEL_TS100

View File

@@ -4,12 +4,13 @@
#include "Settings.h"
#include "Pins.h"
#include "fusbpd.h"
#include "Model_Config.h"
#include "int_n.h"
bool FUSB302_present = false;
void power_probe() {
// If TS80 probe for QC
// If TS80(p) probe for QC
// If TS100 - noop
#if defined(MODEL_TS80)+defined(MODEL_TS80P)>0
#ifdef POW_QC
startQC(systemSettings.voltageDiv);
seekQC((systemSettings.cutoutSetting) ? 120 : 90,
@@ -19,12 +20,12 @@ void power_probe() {
}
void power_check() {
#if defined(MODEL_TS80)+defined(MODEL_TS80P)>0
#ifdef POW_QC
QC_resync();
#endif
}
uint8_t usb_pd_detect() {
#ifdef MODEL_TS80P
#ifdef POW_PD
FUSB302_present = fusb302_detect();
return FUSB302_present;
@@ -32,7 +33,7 @@ uint8_t usb_pd_detect() {
return false;
}
uint8_t pd_irq_read() {
#ifdef MODEL_TS80P
#ifdef POW_PD
return HAL_GPIO_ReadPin(INT_PD_GPIO_Port, INT_PD_Pin) == GPIO_PIN_SET ?
1 : 0;
#endif

View File

@@ -9,6 +9,8 @@
#include "QC3.h"
#include "Settings.h"
#include "stm32f1xx_hal.h"
#include "Model_Config.h"
#ifdef POW_QC
void QC_DPlusZero_Six() {
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); // pull down D+
}
@@ -65,9 +67,9 @@ void QC_Post_Probe_En() {
}
uint8_t QC_DM_PulledDown() { return HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_11) == GPIO_PIN_RESET ? 1 : 0; }
#endif
void QC_resync() {
#if defined(MODEL_TS80) + defined(MODEL_TS80P) >0
#ifdef POW_QC
seekQC((systemSettings.cutoutSetting) ? 120 : 90,
systemSettings.voltageDiv); // Run the QC seek again if we have drifted too much
#endif

View File

@@ -0,0 +1,27 @@
/*
* Software_I2C.h
*
* Created on: 25 Jul 2020
* Author: Ralim
*/
#ifndef BSP_MINIWARE_SOFTWARE_I2C_H_
#define BSP_MINIWARE_SOFTWARE_I2C_H_
#include "Model_Config.h"
#include "BSP.h"
#include "stm32f1xx_hal.h"
#ifdef I2C_SOFT
#define SOFT_SCL_HIGH() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_SET)
#define SOFT_SCL_LOW() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_RESET)
#define SOFT_SDA_HIGH() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_SET)
#define SOFT_SDA_LOW() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_RESET)
#define SOFT_SDA_READ() (HAL_GPIO_ReadPin(SDA2_GPIO_Port,SDA2_Pin)==GPIO_PIN_SET?1:0)
#define SOFT_SCL_READ() (HAL_GPIO_ReadPin(SCL2_GPIO_Port,SCL2_Pin)==GPIO_PIN_SET?1:0)
#define SOFT_I2C_DELAY() {for(int xx=0;xx<100;xx++){asm("nop");}}
#endif
#endif /* BSP_MINIWARE_SOFTWARE_I2C_H_ */

View File

@@ -1,18 +0,0 @@
/*
* UnitSettings.h
*
* Created on: 29 May 2020
* Author: Ralim
*/
#ifndef BSP_MINIWARE_UNITSETTINGS_H_
#define BSP_MINIWARE_UNITSETTINGS_H_
//On the TS80, the LIS accel is mounted backwards
#if defined(MODEL_TS80)+defined(MODEL_TS80P)>0
#define LIS_ORI_FLIP
#endif
#endif /* BSP_MINIWARE_UNITSETTINGS_H_ */

View File

@@ -14,6 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "Model_Config.h"
#ifdef POW_PD
#include "BSP.h"
#include "fusb302b.h"
#include "I2CBB.hpp"
@@ -272,3 +274,9 @@ bool fusb_read_id() {
return false;
return true;
}
uint8_t fusb302_detect() {
//Probe the I2C bus for its address
return I2CBB::probe(FUSB302B_ADDR);
}
#endif

View File

@@ -11,6 +11,7 @@
#include "Pins.h"
#include "I2CBB.hpp"
#include "fusbpd.h"
#include "Model_Config.h"
void preRToSInit() {
/* Reset of all peripherals, Initializes the Flash interface and the Systick.
*/
@@ -20,8 +21,11 @@ void preRToSInit() {
HAL_Delay(50);
HAL_GPIO_WritePin(OLED_RESET_GPIO_Port, OLED_RESET_Pin, GPIO_PIN_SET);
HAL_Delay(50);
#ifdef MODEL_TS80P
#ifdef I2C_SOFT
I2CBB::init();
#endif
#ifdef POW_PD
//Spawn all of the USB-C processors
fusb302_start_processing();
#endif

View File

@@ -4,8 +4,8 @@
* Created on: 13 Jun 2020
* Author: Ralim
*/
#ifdef MODEL_TS80P
#include "Model_Config.h"
#ifdef POW_PD
#include <fusbpd.h>
#include <pd.h>
#include "BSP.h"
@@ -17,10 +17,7 @@
#include "int_n.h"
#include "hard_reset.h"
uint8_t fusb302_detect() {
//Probe the I2C bus for its address
return I2CBB::probe(FUSB302B_ADDR);
}
void fusb302_start_processing() {
/* Initialize the FUSB302B */

View File

@@ -4,17 +4,10 @@
* Created on: 12 Jun 2020
* Author: Ralim
*/
#ifdef MODEL_TS80P
#include "Model_Config.h"
#ifdef I2C_SOFT
#include <I2CBB.hpp>
#include "FreeRTOS.h"
#define SCL_HIGH() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_SET)
#define SCL_LOW() HAL_GPIO_WritePin(SCL2_GPIO_Port, SCL2_Pin, GPIO_PIN_RESET)
#define SDA_HIGH() HAL_GPIO_WritePin(SDA2_GPIO_Port, SDA2_Pin, GPIO_PIN_SET)
#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");}}
SemaphoreHandle_t I2CBB::I2CSemaphore = NULL;
StaticSemaphore_t I2CBB::xSemaphoreBuffer;
SemaphoreHandle_t I2CBB::I2CSemaphore2 = NULL;
@@ -28,8 +21,8 @@ void I2CBB::init() {
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(SDA2_GPIO_Port, &GPIO_InitStruct);
SDA_HIGH();
SCL_HIGH();
SOFT_SDA_HIGH();
SOFT_SCL_HIGH();
I2CSemaphore = xSemaphoreCreateBinaryStatic(&xSemaphoreBuffer);
I2CSemaphore2 = xSemaphoreCreateBinaryStatic(&xSemaphoreBuffer2);
unlock();
@@ -66,8 +59,8 @@ bool I2CBB::Mem_Read(uint16_t DevAddress, uint16_t MemAddress, uint8_t *pData,
unlock();
return false;
}
SCL_LOW();
I2C_DELAY();
SOFT_SCL_LOW();
SOFT_I2C_DELAY();
// stop();
start();
ack = send(DevAddress | 1);
@@ -107,7 +100,7 @@ bool I2CBB::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
}
while (Size) {
resetWatchdog();
bool ack = send(pData[0]);
ack = send(pData[0]);
if (!ack) {
stop();
asm("bkpt");
@@ -133,7 +126,7 @@ void I2CBB::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
return;
}
while (Size) {
bool ack = send(pData[0]);
ack = send(pData[0]);
if (!ack) {
stop();
unlock();
@@ -181,7 +174,7 @@ void I2CBB::TransmitReceive(uint16_t DevAddress, uint8_t *pData_tx,
return;
}
while (Size_tx) {
bool ack = send(pData_tx[0]);
ack = send(pData_tx[0]);
if (!ack) {
stop();
unlock();
@@ -211,24 +204,24 @@ void I2CBB::TransmitReceive(uint16_t DevAddress, uint8_t *pData_tx,
void I2CBB::start() {
/* I2C Start condition, data line goes low when clock is high */
SCL_HIGH();
SDA_HIGH();
I2C_DELAY();
SDA_LOW();
I2C_DELAY();
SCL_LOW();
I2C_DELAY();
SDA_HIGH();
SOFT_SCL_HIGH();
SOFT_SDA_HIGH();
SOFT_I2C_DELAY();
SOFT_SDA_LOW();
SOFT_I2C_DELAY();
SOFT_SCL_LOW();
SOFT_I2C_DELAY();
SOFT_SDA_HIGH();
}
void I2CBB::stop() {
/* I2C Stop condition, clock goes high when data is low */
SDA_LOW();
I2C_DELAY();
SCL_HIGH();
I2C_DELAY();
SDA_HIGH();
I2C_DELAY();
SOFT_SDA_LOW();
SOFT_I2C_DELAY();
SOFT_SCL_HIGH();
SOFT_I2C_DELAY();
SOFT_SDA_HIGH();
SOFT_I2C_DELAY();
}
bool I2CBB::send(uint8_t value) {
@@ -238,7 +231,7 @@ bool I2CBB::send(uint8_t value) {
value <<= 1;
}
SDA_HIGH();
SOFT_SDA_HIGH();
bool ack = (read_bit() == 0);
return ack;
}
@@ -252,7 +245,7 @@ uint8_t I2CBB::read(bool ack) {
B |= read_bit();
}
SDA_HIGH();
SOFT_SDA_HIGH();
if (ack)
write_bit(0);
else
@@ -263,17 +256,17 @@ uint8_t I2CBB::read(bool ack) {
uint8_t I2CBB::read_bit() {
uint8_t b;
SDA_HIGH();
I2C_DELAY();
SCL_HIGH();
I2C_DELAY();
SOFT_SDA_HIGH();
SOFT_I2C_DELAY();
SOFT_SCL_HIGH();
SOFT_I2C_DELAY();
if (SDA_READ())
if (SOFT_SDA_READ())
b = 1;
else
b = 0;
SCL_LOW();
SOFT_SCL_LOW();
return b;
}
@@ -294,15 +287,15 @@ bool I2CBB::lock() {
void I2CBB::write_bit(uint8_t val) {
if (val) {
SDA_HIGH();
SOFT_SDA_HIGH();
} else {
SDA_LOW();
SOFT_SDA_LOW();
}
I2C_DELAY();
SCL_HIGH();
I2C_DELAY();
SCL_LOW();
SOFT_I2C_DELAY();
SOFT_SCL_HIGH();
SOFT_I2C_DELAY();
SOFT_SCL_LOW();
}
void I2CBB::unlock2() {

View File

@@ -7,17 +7,15 @@
#ifndef BSP_MINIWARE_I2CBB_HPP_
#define BSP_MINIWARE_I2CBB_HPP_
#ifdef MODEL_TS80P
#include "Model_Config.h"
#ifdef I2C_SOFT
#include "BSP.h"
#include "Setup.h"
#include "Pins.h"
#include "FreeRTOS.h"
#include "semphr.h"
/*
* Simple static I2C bit-bang class used on the TS80P
* SCL = PA5
* SDA = PA1
*/
#include "Software_I2C.h"
class I2CBB {
public:
static void init();

View File

@@ -191,9 +191,9 @@ void OLED::transitionSecondaryFramebuffer(bool forwardNavigation) {
offset = progress;
memmove(&firstStripPtr[oldStart], &firstStripPtr[oldPrevious],
OLED_WIDTH - progress);
OLED_WIDTH - progress);
memmove(&secondStripPtr[oldStart], &secondStripPtr[oldPrevious],
OLED_WIDTH - progress);
OLED_WIDTH - progress);
memmove(&firstStripPtr[newStart], &firstBackStripPtr[newEnd], progress);
memmove(&secondStripPtr[newStart], &secondBackStripPtr[newEnd],
@@ -213,7 +213,7 @@ void OLED::useSecondaryFramebuffer(bool useSecondary) {
}
void OLED::setRotation(bool leftHanded) {
#if defined( MODEL_TS80) +defined( MODEL_TS80P) > 0
#ifdef OLED_FLIP
leftHanded = !leftHanded;
#endif
if (inLeftHandedMode == leftHanded) {

View File

@@ -59,11 +59,13 @@ void gui_drawTipTemp(bool symbol) {
// Draw tip temp handling unit conversion & tolerance near setpoint
uint16_t Temp = 0;
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF)
if (systemSettings.temperatureInF){
Temp = TipThermoModel::getTipInF();
else
}else
#endif
Temp = TipThermoModel::getTipInC();
{
Temp = TipThermoModel::getTipInC();
}
OLED::printNumber(Temp, 3); // Draw the tip temp out finally
if (symbol) {
@@ -247,7 +249,7 @@ static void gui_solderingTempAdjust() {
if (xTaskGetTickCount() - lastChange > 200)
return; // exit if user just doesn't press anything for a bit
#if defined (MODEL_TS80P)+defined(MODEL_TS80)>0
#ifdef OLED_FLIP
if (!OLED::getRotation()) {
#else
if (OLED::getRotation()) {
@@ -272,7 +274,7 @@ static void gui_solderingTempAdjust() {
OLED::drawSymbol(1);
}
OLED::print(SymbolSpace);
#if defined (MODEL_TS80P)+defined(MODEL_TS80)>0
#ifdef OLED_FLIP
if (!OLED::getRotation()) {
#else
if (OLED::getRotation()) {
@@ -646,9 +648,10 @@ void startGUITask(void const *argument __unused) {
{
//Generate the flipped screen into ram for later use
//flipped is generated by flipping each row
for(int row=0;row<2;row++){
for (int x =0;x<84;x++){
idleScreenBGF[(row*84)+x] =idleScreenBG[(row*84)+(83-x)];
for (int row = 0; row < 2; row++) {
for (int x = 0; x < 84; x++) {
idleScreenBGF[(row * 84) + x] = idleScreenBG[(row * 84)
+ (83 - x)];
}
}
}
@@ -769,7 +772,7 @@ void startGUITask(void const *argument __unused) {
} else {
OLED::setFont(0);
#if defined (MODEL_TS80P)+defined(MODEL_TS80)>0
#ifdef OLED_FLIP
if (!OLED::getRotation()) {
#else
if (OLED::getRotation()) {
@@ -790,7 +793,7 @@ void startGUITask(void const *argument __unused) {
if (tempOnDisplay) {
// draw temp over the start soldering button
// Location changes on screen rotation
#if defined (MODEL_TS80P)+defined(MODEL_TS80)>0
#ifdef OLED_FLIP
if (!OLED::getRotation()) {
#else
if (OLED::getRotation()) {

View File

@@ -1,4 +1,5 @@
#pragma once
#include "Model_Config.h"
/**
* Configuration.h
* Define here your default pre settings for TS80 or TS100