[lightning-ln882h] Add support for Lightning LN882H family (#312)
* fix mbedtls bad pointer in function call (prototype mismatch) * fix issue with weak families functions implemented in static library, it will never be linked. fixed by redefining prototypes inside families * [ln882x] add support for lightning ln882x & ln882h families * add i2c (wire) support * add analog (adc) support * add watchdog support * [ln882x] changed default uart 0/1 pins; added board wl2s * [ln882x] fix IRQ & ADC pins * [ln882x] boards cosmetic * [ln882x] wifi sta use otp mac addr by default; re-enabled wifi powersave mode * [ln882x] clang-format clean code * [ln882x] clang-format clean code * Update families.json * Apply suggestions from code review * [ln882x] reformat json board files * [ln882x] os_queue cleanup * [ln882x] removed Beken auto-download command * [ln882x] removed personal script file * [ln882x] removed unusefull pi section in debugging.md * [ln882x] removed Arduino.h and changed private I2C definition * [ln882x] updated README.md * [ln882x] changed pin naming scheme to PA/PB * [ln882x] clean code * [ln882x] clean code * [ln882x] add ota image verification * Update push-dev.yml * [ln882x] fix boards ADC missing inputs] * [ln882x] removed reg_xxx fixup files and use include guards instead * [ln882x] cleanup code * [ln882x] cleanup code * [ln882x] fix lt_init weak functions linking * [ln882x] revert lt_api.h modification, fixed with previous commit * [ln882x] setup UF2 firmware for flasher with partitions * [ln882x] update README.md * [ln882x] include ln_wifi.h and ln_serial.h to avoid including bad headers on case insensitive systems * [ln882x] Replace RingBuffer by SerialRingBuffer * [ln882x] clang-format * [ln882x] update README.md * Apply suggestions from code review * Reformat board JSON files * Add mkdocs link redirect * Update ltchiptool to v4.12.0 --------- Co-authored-by: Kuba Szczodrzyński <kuba@szczodrzynski.pl>
This commit is contained in:
8
cores/lightning-ln882h/base/api/lt_cpu.c
Normal file
8
cores/lightning-ln882h/base/api/lt_cpu.c
Normal file
@@ -0,0 +1,8 @@
|
||||
/* Copyright (c) Etienne Le Cousin 2024-02-24. */
|
||||
|
||||
#include <libretiny.h>
|
||||
#include <sdk_private.h>
|
||||
|
||||
const char *lt_cpu_get_core_type() {
|
||||
return "ARM Cortex-M4F (ARMv7E-M)";
|
||||
}
|
||||
27
cores/lightning-ln882h/base/api/lt_device.c
Normal file
27
cores/lightning-ln882h/base/api/lt_device.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/* Copyright (c) Etienne Le Cousin 2024-03-03. */
|
||||
|
||||
#include <libretiny.h>
|
||||
#include <sdk_private.h>
|
||||
|
||||
void lt_get_device_mac(uint8_t *mac) {
|
||||
ln_fotp_get_mac_val(mac);
|
||||
}
|
||||
|
||||
void lt_reboot() {
|
||||
ln_chip_reboot();
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
lt_reboot_reason_t lt_get_reboot_reason() {
|
||||
chip_reboot_cause_t reason = ln_chip_get_reboot_cause();
|
||||
switch (reason) {
|
||||
case CHIP_REBOOT_POWER_ON:
|
||||
return REBOOT_REASON_POWER;
|
||||
case CHIP_REBOOT_SOFTWARE:
|
||||
return REBOOT_REASON_SOFTWARE;
|
||||
case CHIP_REBOOT_WATCHDOG:
|
||||
return REBOOT_REASON_WATCHDOG;
|
||||
default:
|
||||
return REBOOT_REASON_UNKNOWN;
|
||||
}
|
||||
}
|
||||
15
cores/lightning-ln882h/base/api/lt_flash.c
Normal file
15
cores/lightning-ln882h/base/api/lt_flash.c
Normal file
@@ -0,0 +1,15 @@
|
||||
/* Copyright (c) Etienne Le Cousin 2024-03-03. */
|
||||
|
||||
#include <libretiny.h>
|
||||
#include <sdk_private.h>
|
||||
|
||||
uint32_t hal_flash_read_id(void);
|
||||
|
||||
lt_flash_id_t lt_flash_get_id() {
|
||||
lt_flash_id_t id;
|
||||
uint32_t fl_id = hal_flash_read_id();
|
||||
id.manufacturer_id = (uint8_t)(fl_id >> 16);
|
||||
id.chip_id = (uint8_t)(fl_id >> 8);
|
||||
id.chip_size_id = (uint8_t)(fl_id >> 0);
|
||||
return id;
|
||||
}
|
||||
58
cores/lightning-ln882h/base/api/lt_init.c
Normal file
58
cores/lightning-ln882h/base/api/lt_init.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/* Copyright (c) Etienne Le Cousin 2024-02-24. */
|
||||
|
||||
#include <libretiny.h>
|
||||
#include <sdk_private.h>
|
||||
|
||||
extern uint8_t uart_print_port;
|
||||
extern Serial_t m_LogSerial;
|
||||
|
||||
static void lt_init_log(void) {
|
||||
// default LT print port
|
||||
uart_print_port = LT_UART_DEFAULT_LOGGER;
|
||||
// default SDK print port
|
||||
serial_init(&m_LogSerial, LT_UART_DEFAULT_PORT, CFG_UART_BAUDRATE_LOG, NULL);
|
||||
}
|
||||
|
||||
void lt_init_family() {
|
||||
// 0. check reboot cause
|
||||
ln_chip_get_reboot_cause();
|
||||
|
||||
// 1. sys clock,interrupt
|
||||
SetSysClock();
|
||||
set_interrupt_priority();
|
||||
switch_global_interrupt(HAL_ENABLE);
|
||||
ln_runtime_measure_init();
|
||||
|
||||
// 2. register os heap mem
|
||||
OS_DefineHeapRegions();
|
||||
|
||||
// 3. log init
|
||||
lt_init_log();
|
||||
|
||||
cm_backtrace_init("LibreTiny - LN882H", "HW_V1.0", "SW_V1.0");
|
||||
|
||||
if (NVDS_ERR_OK != ln_nvds_init(FLASH_NVDS_OFFSET)) {
|
||||
LT_E("NVDS init failed!");
|
||||
}
|
||||
|
||||
if (KV_ERR_NONE != ln_kv_port_init(FLASH_KV_OFFSET, (FLASH_KV_OFFSET + FLASH_KV_LENGTH))) {
|
||||
LT_E("KV init failed!");
|
||||
}
|
||||
|
||||
// init system parameter
|
||||
sysparam_integrity_check_all();
|
||||
|
||||
ln_pm_sleep_mode_set(ACTIVE);
|
||||
// ln_pm_always_clk_disable_select(CLK_G_I2S | CLK_G_WS2811 | CLK_G_SDIO);
|
||||
/*ln_pm_always_clk_disable_select(CLK_G_I2S | CLK_G_WS2811 | CLK_G_SDIO | CLK_G_AES);
|
||||
ln_pm_lightsleep_clk_disable_select(CLK_G_GPIOA | CLK_G_GPIOB | CLK_G_SPI0 | CLK_G_SPI1 | CLK_G_I2C0 |
|
||||
CLK_G_UART1 | CLK_G_UART2 | CLK_G_WDT | CLK_G_TIM1 | CLK_G_TIM2 | CLK_G_MAC |
|
||||
CLK_G_DMA | CLK_G_RF | CLK_G_ADV_TIMER| CLK_G_TRNG);*/
|
||||
}
|
||||
|
||||
void lt_init_arduino() {
|
||||
#if LT_AUTO_DOWNLOAD_REBOOT && LT_ARD_HAS_SERIAL && LT_HW_UART0
|
||||
// initialize auto-download-reboot parser
|
||||
Serial0.begin(115200);
|
||||
#endif
|
||||
}
|
||||
8
cores/lightning-ln882h/base/api/lt_mem.c
Normal file
8
cores/lightning-ln882h/base/api/lt_mem.c
Normal file
@@ -0,0 +1,8 @@
|
||||
/* Copyright (c) Etienne Le Cousin 2024-02-24. */
|
||||
|
||||
#include <libretiny.h>
|
||||
#include <sdk_private.h>
|
||||
|
||||
uint32_t lt_ram_get_size() {
|
||||
return 296 * 1024;
|
||||
}
|
||||
45
cores/lightning-ln882h/base/api/lt_ota.c
Normal file
45
cores/lightning-ln882h/base/api/lt_ota.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/* Copyright (c) Etienne Le Cousin 2024-12-21. */
|
||||
|
||||
#include <libretiny.h>
|
||||
#include <ota_image.h>
|
||||
#include <sdk_private.h>
|
||||
|
||||
lt_ota_type_t lt_ota_get_type() {
|
||||
return OTA_TYPE_SINGLE;
|
||||
}
|
||||
|
||||
bool lt_ota_is_valid(uint8_t index) {
|
||||
image_hdr_t ota_header;
|
||||
|
||||
if (OTA_ERR_NONE != image_header_fast_read(FLASH_OTA_OFFSET, &ota_header)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (OTA_ERR_NONE != image_header_verify(&ota_header)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (OTA_ERR_NONE != image_body_verify(FLASH_OTA_OFFSET, &ota_header)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t lt_ota_dual_get_current() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t lt_ota_dual_get_stored() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void lt_ota_set_write_protect(uf2_ota_t *uf2) {
|
||||
LT_DM(OTA, "lt_ota_set_write_protect");
|
||||
ln_nvds_set_ota_upg_state(UPG_STATE_DOWNLOAD_ING);
|
||||
}
|
||||
|
||||
bool lt_ota_switch(bool revert) {
|
||||
LT_DM(OTA, "lt_ota_switch(%d)", revert);
|
||||
ln_nvds_set_ota_upg_state(UPG_STATE_DOWNLOAD_OK);
|
||||
return true;
|
||||
}
|
||||
43
cores/lightning-ln882h/base/api/lt_wdt.c
Normal file
43
cores/lightning-ln882h/base/api/lt_wdt.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/* Copyright (c) Etienne Le Cousin 2025-01-19. */
|
||||
|
||||
#include <libretiny.h>
|
||||
#include <sdk_private.h>
|
||||
|
||||
bool lt_wdt_enable(uint32_t timeout) {
|
||||
|
||||
wdt_top_value_t wdt_top_value = 0;
|
||||
for (uint8_t i = 0; i < 15; i++) {
|
||||
if ((0x100UL << i) < (timeout * 32768 / 1000))
|
||||
wdt_top_value = i;
|
||||
}
|
||||
|
||||
wdt_init_t_def wdt_init;
|
||||
memset(&wdt_init, 0, sizeof(wdt_init));
|
||||
wdt_init.wdt_rmod = WDT_RMOD_1;
|
||||
wdt_init.wdt_rpl = WDT_RPL_32_PCLK;
|
||||
wdt_init.top = wdt_top_value;
|
||||
|
||||
hal_wdt_init(WDT_BASE, &wdt_init);
|
||||
|
||||
/* Configure Interrupt */
|
||||
NVIC_SetPriority(WDT_IRQn, 4);
|
||||
NVIC_EnableIRQ(WDT_IRQn);
|
||||
|
||||
/* Watchdog enable */
|
||||
/* Note : Watchdog cannot be disabled */
|
||||
hal_wdt_en(WDT_BASE, HAL_ENABLE);
|
||||
|
||||
/* Start feeding */
|
||||
hal_wdt_cnt_restart(WDT_BASE);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void lt_wdt_disable() {
|
||||
hal_wdt_deinit();
|
||||
hal_wdt_en(WDT_BASE, HAL_DISABLE);
|
||||
}
|
||||
|
||||
void lt_wdt_feed() {
|
||||
hal_wdt_cnt_restart(WDT_BASE);
|
||||
}
|
||||
Reference in New Issue
Block a user