[lightning-ln882h] Fix analog read, add Wi-Fi calibration, add generic board (#319)
* [ln882x] fix analog read * [ln882h] add wifi temp calibration task * [ln882h] add generic-ln882hki board * [ln882h] fix wifi null pointer crash
This commit is contained in:
@@ -175,7 +175,7 @@ bool WiFiClass::setMacAddress(const uint8_t *mac) {
|
||||
}
|
||||
|
||||
const String WiFiClass::SSID() {
|
||||
const char *ssid = NULL;
|
||||
const char *ssid = "";
|
||||
const uint8_t *bssid = NULL;
|
||||
wifi_get_sta_conn_info(&ssid, &bssid);
|
||||
return ssid;
|
||||
|
||||
@@ -5,9 +5,13 @@
|
||||
|
||||
extern "C" {
|
||||
|
||||
#define MAIN_TASK_STACK_SIZE 8192
|
||||
extern void cal_temp_app_task_entry();
|
||||
|
||||
#define MAIN_TASK_STACK_SIZE 8192
|
||||
#define TEMP_APP_TASK_STACK_SIZE 1024
|
||||
|
||||
static OS_Thread_t g_mainTask_thread;
|
||||
static OS_Thread_t g_temp_cal_thread;
|
||||
|
||||
bool startMainTask() {
|
||||
OS_Status ret = OS_ThreadCreate(
|
||||
@@ -21,6 +25,20 @@ bool startMainTask() {
|
||||
|
||||
if (ret != OS_OK)
|
||||
return false;
|
||||
|
||||
ret = OS_ThreadCreate(
|
||||
&g_temp_cal_thread,
|
||||
"TempCal",
|
||||
(OS_ThreadEntry_t)cal_temp_app_task_entry,
|
||||
NULL,
|
||||
OS_PRIORITY_BELOW_NORMAL,
|
||||
TEMP_APP_TASK_STACK_SIZE
|
||||
);
|
||||
|
||||
if (ret != OS_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
OS_ThreadStartScheduler();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -43,12 +43,11 @@ static adc_ch_t pinToAdcCh(uint32_t gpio) {
|
||||
return ADC_CH0;
|
||||
}
|
||||
|
||||
// WARN: adc values are quite bad (zero value of ~ 1000lsb and full scale value ~ 3450lsb)
|
||||
uint16_t analogReadVoltage(pin_size_t pinNumber) {
|
||||
uint16_t ret = 0;
|
||||
pinCheckGetInfo(pinNumber, PIN_ADC, 0);
|
||||
|
||||
hal_gpio_pin_mode_set(GPIO_GET_BASE(pin->gpio), pin->gpio, GPIO_MODE_ANALOG);
|
||||
hal_gpio_pin_mode_set(GPIO_GET_BASE(pin->gpio), GPIO_GET_PIN(pin->gpio), GPIO_MODE_ANALOG);
|
||||
|
||||
adc_ch_t ch = pinToAdcCh(pin->gpio);
|
||||
adc_init_t_def adc_init;
|
||||
@@ -72,7 +71,7 @@ uint16_t analogReadVoltage(pin_size_t pinNumber) {
|
||||
|
||||
hal_adc_clr_conv_status(ADC_BASE, ch);
|
||||
|
||||
return (uint16_t)(3300UL * ret / 4095);
|
||||
return (uint16_t)(3700UL * ret / 4095);
|
||||
}
|
||||
|
||||
uint16_t analogReadMaxVoltage(pin_size_t pinNumber) {
|
||||
|
||||
57
cores/lightning-ln882h/base/fixups/wifi_cal.c
Normal file
57
cores/lightning-ln882h/base/fixups/wifi_cal.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/* Copyright (c) Etienne Le Cousin 2025-05-04. */
|
||||
|
||||
#include <sdk_private.h>
|
||||
|
||||
void cal_adc_init(void)
|
||||
{
|
||||
adc_init_t_def adc_init;
|
||||
|
||||
memset(&adc_init, 0, sizeof(adc_init_t_def));
|
||||
adc_init.adc_ch = ADC_CH0;
|
||||
adc_init.adc_conv_mode = ADC_CONV_MODE_CONTINUE;
|
||||
adc_init.adc_presc = 0xFF;
|
||||
adc_init.adc_ov_smp_ratio = ADC_OVER_SAMPLING_RATIO_X8;
|
||||
adc_init.adc_ov_smp_ratio_en = ADC_OVER_SAMPLING_EN_STATUS_BIT0;
|
||||
hal_adc_init(ADC_BASE, &adc_init);
|
||||
|
||||
hal_adc_en(ADC_BASE, HAL_ENABLE);
|
||||
|
||||
hal_adc_start_conv(ADC_BASE);
|
||||
}
|
||||
|
||||
uint16_t cal_adc_read(adc_ch_t ch)
|
||||
{
|
||||
uint16_t read_adc = 0;
|
||||
|
||||
while(hal_adc_get_conv_status(ADC_BASE, ch) == 0);
|
||||
|
||||
read_adc = hal_adc_get_data(ADC_BASE, ch);
|
||||
|
||||
hal_adc_clr_conv_status(ADC_BASE,ch);
|
||||
|
||||
return read_adc;
|
||||
}
|
||||
|
||||
void cal_temp_app_task_entry()
|
||||
{
|
||||
int8_t cap_comp = 0;
|
||||
uint16_t adc_val = 0;
|
||||
|
||||
if (NVDS_ERR_OK == ln_nvds_get_xtal_comp_val((uint8_t *)&cap_comp)) {
|
||||
if ((uint8_t)cap_comp == 0xFF) {
|
||||
cap_comp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
cal_adc_init();
|
||||
|
||||
wifi_temp_cal_init(cal_adc_read(ADC_CH0), cap_comp);
|
||||
|
||||
while (1)
|
||||
{
|
||||
OS_MsDelay(1000);
|
||||
|
||||
adc_val = cal_adc_read(ADC_CH0);
|
||||
wifi_do_temp_cal_period(adc_val);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user