Pinecil V2 (#1341)
* 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
This commit is contained in:
157
source/Core/BSP/Pinecilv2/Setup.cpp
Normal file
157
source/Core/BSP/Pinecilv2/Setup.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Setup.c
|
||||
*
|
||||
* Created on: 29Aug.,2017
|
||||
* Author: Ben V. Brown
|
||||
*/
|
||||
#include "Setup.h"
|
||||
#include "BSP.h"
|
||||
#include "Debug.h"
|
||||
#include "FreeRTOSConfig.h"
|
||||
#include "Pins.h"
|
||||
|
||||
#include "IRQ.h"
|
||||
#include "history.hpp"
|
||||
#include <string.h>
|
||||
#define ADC_NORM_SAMPLES 16
|
||||
#define ADC_FILTER_LEN 4
|
||||
uint16_t ADCReadings[ADC_NORM_SAMPLES]; // room for 32 lots of the pair of readings
|
||||
|
||||
// Functions
|
||||
|
||||
void setup_timer_scheduler(void);
|
||||
void setup_pwm(void);
|
||||
void setup_adc(void);
|
||||
void hardware_init() {
|
||||
gpio_set_mode(OLED_RESET_Pin, GPIO_OUTPUT_MODE);
|
||||
gpio_set_mode(KEY_A_Pin, GPIO_INPUT_PD_MODE);
|
||||
gpio_set_mode(KEY_B_Pin, GPIO_INPUT_PD_MODE);
|
||||
gpio_set_mode(TMP36_INPUT_Pin, GPIO_INPUT_MODE);
|
||||
gpio_set_mode(TIP_TEMP_Pin, GPIO_INPUT_MODE);
|
||||
gpio_set_mode(VIN_Pin, GPIO_INPUT_MODE);
|
||||
|
||||
gpio_set_mode(TIP_RESISTANCE_SENSE, GPIO_OUTPUT_MODE);
|
||||
gpio_write(TIP_RESISTANCE_SENSE, 0);
|
||||
|
||||
MSG((char *)"Pine64 Pinecilv2 Starting\r\n");
|
||||
setup_timer_scheduler();
|
||||
setup_adc();
|
||||
setup_pwm();
|
||||
I2C_ClockSet(I2C0_ID, 200000); // Sets clock to around 175kHz
|
||||
TIMER_SetCompValue(TIMER_CH0, TIMER_COMP_ID_1, 0);
|
||||
}
|
||||
void setup_pwm(void) {
|
||||
// Setup PWM we use for driving the tip
|
||||
PWM_CH_CFG_Type cfg = {
|
||||
PWM_Channel, // channel
|
||||
PWM_CLK_XCLK, // Clock
|
||||
PWM_STOP_ABRUPT, // Stop mode
|
||||
PWM_POL_NORMAL, // Normal Polarity
|
||||
60, // Clock Div
|
||||
100, // Period
|
||||
0, // Thres 1 - start at beginng
|
||||
50, // Thres 2 - turn off at 50%
|
||||
0, // Interrupt pulse count
|
||||
};
|
||||
|
||||
PWM_Channel_Init(&cfg);
|
||||
PWM_Channel_Disable(PWM_Channel);
|
||||
}
|
||||
|
||||
const ADC_Chan_Type adc_tip_pos_chans[]
|
||||
= {TIP_TEMP_ADC_CHANNEL, TMP36_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, VIN_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, TMP36_ADC_CHANNEL, TIP_TEMP_ADC_CHANNEL, VIN_ADC_CHANNEL};
|
||||
const ADC_Chan_Type adc_tip_neg_chans[] = {ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND, ADC_CHAN_GND};
|
||||
static_assert(sizeof(adc_tip_pos_chans) == sizeof(adc_tip_neg_chans));
|
||||
|
||||
void setup_adc(void) {
|
||||
//
|
||||
ADC_CFG_Type adc_cfg = {};
|
||||
ADC_FIFO_Cfg_Type adc_fifo_cfg = {};
|
||||
|
||||
CPU_Interrupt_Disable(GPADC_DMA_IRQn);
|
||||
|
||||
ADC_IntMask(ADC_INT_ALL, MASK);
|
||||
|
||||
adc_cfg.clkDiv = ADC_CLK_DIV_4;
|
||||
adc_cfg.vref = ADC_VREF_3P2V;
|
||||
adc_cfg.resWidth = ADC_DATA_WIDTH_14_WITH_64_AVERAGE;
|
||||
adc_cfg.inputMode = ADC_INPUT_SINGLE_END;
|
||||
adc_cfg.v18Sel = ADC_V18_SEL_1P72V;
|
||||
adc_cfg.v11Sel = ADC_V11_SEL_1P1V;
|
||||
adc_cfg.gain1 = ADC_PGA_GAIN_NONE;
|
||||
adc_cfg.gain2 = ADC_PGA_GAIN_NONE;
|
||||
adc_cfg.chopMode = ADC_CHOP_MOD_AZ_ON;
|
||||
adc_cfg.biasSel = ADC_BIAS_SEL_MAIN_BANDGAP;
|
||||
adc_cfg.vcm = ADC_PGA_VCM_1P6V;
|
||||
adc_cfg.offsetCalibEn = ENABLE;
|
||||
adc_cfg.offsetCalibVal = 0;
|
||||
|
||||
ADC_Disable();
|
||||
ADC_Enable();
|
||||
ADC_Reset();
|
||||
|
||||
ADC_Init(&adc_cfg);
|
||||
adc_fifo_cfg.dmaEn = DISABLE;
|
||||
adc_fifo_cfg.fifoThreshold = ADC_FIFO_THRESHOLD_8;
|
||||
ADC_FIFO_Cfg(&adc_fifo_cfg);
|
||||
ADC_MIC_Bias_Disable();
|
||||
ADC_Tsen_Disable();
|
||||
|
||||
// Enable FiFo IRQ
|
||||
Interrupt_Handler_Register(GPADC_DMA_IRQn, adc_fifo_irq);
|
||||
ADC_IntMask(ADC_INT_FIFO_READY, UNMASK);
|
||||
CPU_Interrupt_Enable(GPADC_DMA_IRQn);
|
||||
ADC_Stop();
|
||||
ADC_FIFO_Clear();
|
||||
ADC_Scan_Channel_Config(adc_tip_pos_chans, adc_tip_neg_chans, sizeof(adc_tip_pos_chans) / sizeof(ADC_Chan_Type), DISABLE);
|
||||
}
|
||||
|
||||
void setup_timer_scheduler() {
|
||||
TIMER_Disable(TIMER_CH0);
|
||||
|
||||
TIMER_CFG_Type cfg = {
|
||||
TIMER_CH0, // Channel
|
||||
TIMER_CLKSRC_32K, // Clock source
|
||||
TIMER_PRELOAD_TRIG_COMP2, // Trigger
|
||||
TIMER_COUNT_PRELOAD, // Counter mode
|
||||
22, // Clock div
|
||||
(uint16_t)(powerPWM + holdoffTicks), // CH0 compare (adc)
|
||||
0, // CH1 compare (pwm out)
|
||||
(uint16_t)(powerPWM + tempMeasureTicks + holdoffTicks), // CH2 comapre (total period)
|
||||
0, // Preload
|
||||
};
|
||||
TIMER_Init(&cfg);
|
||||
|
||||
Timer_Int_Callback_Install(TIMER_CH0, TIMER_INT_COMP_0, timer0_comp0_callback);
|
||||
Timer_Int_Callback_Install(TIMER_CH0, TIMER_INT_COMP_1, timer0_comp1_callback);
|
||||
Timer_Int_Callback_Install(TIMER_CH0, TIMER_INT_COMP_2, timer0_comp2_callback);
|
||||
|
||||
TIMER_ClearIntStatus(TIMER_CH0, TIMER_COMP_ID_0);
|
||||
TIMER_ClearIntStatus(TIMER_CH0, TIMER_COMP_ID_1);
|
||||
TIMER_ClearIntStatus(TIMER_CH0, TIMER_COMP_ID_2);
|
||||
|
||||
TIMER_IntMask(TIMER_CH0, TIMER_INT_COMP_0, UNMASK);
|
||||
TIMER_IntMask(TIMER_CH0, TIMER_INT_COMP_1, UNMASK);
|
||||
TIMER_IntMask(TIMER_CH0, TIMER_INT_COMP_2, UNMASK);
|
||||
CPU_Interrupt_Enable(TIMER_CH0_IRQn);
|
||||
TIMER_Enable(TIMER_CH0);
|
||||
// switchToSlowPWM();
|
||||
}
|
||||
|
||||
void setupFUSBIRQ() {
|
||||
|
||||
gpio_set_mode(FUSB302_IRQ_Pin, GPIO_SYNC_FALLING_TRIGER_INT_MODE);
|
||||
CPU_Interrupt_Disable(GPIO_INT0_IRQn);
|
||||
Interrupt_Handler_Register(GPIO_INT0_IRQn, GPIO_IRQHandler);
|
||||
CPU_Interrupt_Enable(GPIO_INT0_IRQn);
|
||||
gpio_irq_enable(FUSB302_IRQ_Pin, ENABLE);
|
||||
}
|
||||
|
||||
void vAssertCalled(void) {
|
||||
MSG((char *)"vAssertCalled\r\n");
|
||||
PWM_Channel_Disable(PWM_Channel);
|
||||
gpio_set_mode(PWM_Out_Pin, GPIO_INPUT_PD_MODE);
|
||||
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
Reference in New Issue
Block a user