Skip to content

Commit

Permalink
Merge pull request #291 from fishybow/fishybow
Browse files Browse the repository at this point in the history
Improved board management / dependency
  • Loading branch information
solosky authored Nov 20, 2024
2 parents 81cb89b + 9df0cc9 commit a478552
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 186 deletions.
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"${workspaceFolder}/fw/application/config/sdk_config.h"
],
"defines": [
"BOARD_PCA10056",
"BOARD_CUSTOM",
"FLOAT_ABI_HARD",
"NRF52",
"NRF52832_XXAA",
Expand Down
2 changes: 1 addition & 1 deletion fw/application/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"${workspaceFolder}/config/sdk_config.h"
],
"defines": [
"BOARD_PCA10056",
"BOARD_CUSTOM",
"FLOAT_ABI_HARD",
"NRF52",
"NRF52832_XXAA",
Expand Down
4 changes: 2 additions & 2 deletions fw/application/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ CFLAGS += $(OPT)
CFLAGS += -DAPP_TIMER_V2
CFLAGS += -DAPP_TIMER_V2_RTC1_ENABLED
#CFLAGS += -DBOARD_PCA10040
CFLAGS += -DCUSTOM_BOARD_INC=boards_defines
CFLAGS += -DBOARD_CUSTOM
#CFLAGS += -DCONFIG_GPIO_AS_PINRESET
CFLAGS += -DFLOAT_ABI_HARD
CFLAGS += -DNRF52
Expand Down Expand Up @@ -657,7 +657,7 @@ ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
ASMFLAGS += -DAPP_TIMER_V2
ASMFLAGS += -DAPP_TIMER_V2_RTC1_ENABLED
# ASMFLAGS += -DBOARD_PCA10040
ASMFLAGS += -DCUSTOM_BOARD_INC=am_board
ASMFLAGS += -DBOARD_CUSTOM
# ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
ASMFLAGS += -DFLOAT_ABI_HARD
ASMFLAGS += -DNRF52
Expand Down
19 changes: 8 additions & 11 deletions fw/application/src/app/settings/scene/settings_scene.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@

#include "mui_scene_dispatcher.h"

#include "boards.h"
#include "settings_scene.h"
#include "boards_defines.h"


#define ADD_SCENE(prefix, name, id) \
void prefix##_scene_##name##_on_enter(void*); \
void prefix##_scene_##name##_on_exit(void* context);
#define ADD_SCENE(prefix, name, id) \
void prefix##_scene_##name##_on_enter(void *); \
void prefix##_scene_##name##_on_exit(void *context);
#include "settings_scene_config.h"
#undef ADD_SCENE

const mui_scene_t settings_scene_defines[] = {

#define ADD_SCENE(prefix, name, id) \
{ \
.scene_id = (SETTINGS_SCENE_##id), \
.enter_cb = prefix##_scene_##name##_on_enter, \
.exit_cb = prefix##_scene_##name##_on_exit \
}, \
#define ADD_SCENE(prefix, name, id) \
{.scene_id = (SETTINGS_SCENE_##id), \
.enter_cb = prefix##_scene_##name##_on_enter, \
.exit_cb = prefix##_scene_##name##_on_exit},

#include "settings_scene_config.h"
#undef ADD_SCENE
Expand Down
7 changes: 2 additions & 5 deletions fw/application/src/app/settings/scene/settings_scene.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef AMIIBO_SCENE_H
#define AMIIBO_SCENE_H

#include "boards.h"
#include "mui_scene_dispatcher.h"
#include "boards_defines.h"

// Generate scene id and total number
#define ADD_SCENE(prefix, name, id) SETTINGS_SCENE_##id,
Expand All @@ -14,7 +14,4 @@ typedef enum {

extern const mui_scene_t settings_scene_defines[];




#endif
#endif
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/*
* am_board.h
*
* Created on: 2021年8月22日
* Author: solos
*/
#ifndef BOARD_DEFINES_H_
#define BOARD_DEFINES_H_
* custom_board.h
*
* Created on: 2021年8月22日
* Author: solos
*/
#ifndef CUSTOM_BOARD_H_
#define CUSTOM_BOARD_H_
#ifdef __cplusplus
extern "C" {
#endif


#if defined(BOARD_OLED)
#include "boards/board_oled.h"
#elif defined(BOARD_LCD)
Expand All @@ -23,4 +22,4 @@ extern "C" {
}
#endif

#endif /* AM_BOARD_H_ */
#endif // CUSTOM_BOARD_H_
13 changes: 4 additions & 9 deletions fw/application/src/hal/hal_spi_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "app_error.h"
#include "app_util_platform.h"
#include "boards_defines.h"
#include "boards.h"
#include <stdio.h>

#include <nrfx_spim.h>
Expand All @@ -12,12 +12,10 @@
#include "nrf_gpio.h"
#include "nrf_log.h"


#define SPI_INSTANCE 0

static const nrfx_spim_t m_spi = NRFX_SPIM_INSTANCE(SPI_INSTANCE);


void hal_spi_bus_init() {
ret_code_t err_code;

Expand Down Expand Up @@ -47,22 +45,19 @@ uint32_t hal_spi_bus_xfer(spi_transaction_t *p_trans) {
uint32_t err_code = NRF_SUCCESS;
nrfx_spim_xfer_desc_t spim_xfer_desc;

uint32_t max_xfer_bytes =
p_trans->tx_length > p_trans->rx_length ? p_trans->tx_length : p_trans->rx_length;
uint32_t max_xfer_bytes = p_trans->tx_length > p_trans->rx_length ? p_trans->tx_length : p_trans->rx_length;
for (uint32_t i = 0; i < max_xfer_bytes; i += 128) {

if (i < p_trans->tx_length) {
spim_xfer_desc.p_tx_buffer = p_trans->p_tx_buffer + i;
spim_xfer_desc.tx_length =
p_trans->tx_length - i < 128 ? p_trans->tx_length - i : 128;
spim_xfer_desc.tx_length = p_trans->tx_length - i < 128 ? p_trans->tx_length - i : 128;
} else {
spim_xfer_desc.p_tx_buffer = NULL;
spim_xfer_desc.tx_length = 0;
}
if (i < p_trans->rx_length) {
spim_xfer_desc.p_rx_buffer = p_trans->p_rx_buffer + i;
spim_xfer_desc.rx_length =
p_trans->rx_length - i < 128 ? p_trans->rx_length - i : 128;
spim_xfer_desc.rx_length = p_trans->rx_length - i < 128 ? p_trans->rx_length - i : 128;
} else {
spim_xfer_desc.p_rx_buffer = NULL;
spim_xfer_desc.rx_length = 0;
Expand Down
88 changes: 41 additions & 47 deletions fw/application/src/hal/hal_spi_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "nrf_log.h"
#include "nrf_log_ctrl.h"

#include "boards_defines.h"
#include "boards.h"

#define PAGE_SIZE 256
#define CMD_ADDR_SIZE 4
Expand Down Expand Up @@ -41,12 +41,11 @@
#define MTC_W25Q64_DW (0x6017) /* W25Q64DW */
#define MTC_W25Q128_BV (0x4018) /* W25Q128BV */
#define MTC_W25Q256_FV (TBD) /* W25Q256FV */
#define MTC_MX25L25645_GM2I (0x2019) /* MX25L25645GM2I-10G */
#define MTC_MX25L25645_GM2I (0x2019) /* MX25L25645GM2I-10G */

static spi_device_t m_dev;

static inline void hal_spi_flash_write_read(uint8_t *tx_data, uint8_t tx_len,
uint8_t *rx_data, uint32_t rx_len) {
static inline void hal_spi_flash_write_read(uint8_t *tx_data, uint8_t tx_len, uint8_t *rx_data, uint32_t rx_len) {
hal_spi_bus_aquire(&m_dev);

spi_transaction_t trans_tx = {
Expand Down Expand Up @@ -74,8 +73,7 @@ static inline void hal_spi_flash_write_read(uint8_t *tx_data, uint8_t tx_len,
hal_spi_bus_release(&m_dev);
}

static inline void hal_spi_flash_write_write(uint8_t *tx_data, uint8_t tx_len,
uint8_t *tx_data2, uint32_t tx_len2) {
static inline void hal_spi_flash_write_write(uint8_t *tx_data, uint8_t tx_len, uint8_t *tx_data2, uint32_t tx_len2) {
hal_spi_bus_aquire(&m_dev);

spi_transaction_t trans_tx = {
Expand Down Expand Up @@ -150,47 +148,46 @@ ret_code_t hal_spi_flash_info(flash_info_t *info) {
memory_type_capacity = (memory_type_capacity << 8) | rx[2];

switch (memory_type_capacity) {
case MTC_MX25L25645_GM2I:
NRF_LOG_INFO("MX25L25645GM2I-10G detection");
info->block_count = 8192;
break;
case MTC_W25Q128_BV:
NRF_LOG_INFO("W25Q128BV detection");
info->block_count = 4096;
break;
case MTC_W25Q64_BV_CV:
NRF_LOG_INFO("W25Q64BV or W25Q64CV detection");
info->block_count = 2048;
break;
case MTC_W25Q64_DW:
NRF_LOG_INFO("W25Q64DW detection");
info->block_count = 2048;
break;
case MTC_W25Q32_BV:
NRF_LOG_INFO("W25Q32BV detection");
info->block_count = 1024;
break;
case MTC_W25Q32_DW:
NRF_LOG_INFO("W25Q32DW detection");
info->block_count = 1024;
break;
case MTC_W25Q16_BV_CL_CV:
NRF_LOG_INFO("W25Q16BV or W25Q16CL or W25Q16CV detection");
info->block_count = 512;
break;
case MTC_W25Q16_DW:
NRF_LOG_INFO("W25Q16DW detection");
info->block_count = 512;
break;
default:
NRF_LOG_INFO("Memory Capacity error! %d", memory_type_capacity);
info->block_count = 0;
return NRF_ERROR_INVALID_PARAM;
case MTC_MX25L25645_GM2I:
NRF_LOG_INFO("MX25L25645GM2I-10G detection");
info->block_count = 8192;
break;
case MTC_W25Q128_BV:
NRF_LOG_INFO("W25Q128BV detection");
info->block_count = 4096;
break;
case MTC_W25Q64_BV_CV:
NRF_LOG_INFO("W25Q64BV or W25Q64CV detection");
info->block_count = 2048;
break;
case MTC_W25Q64_DW:
NRF_LOG_INFO("W25Q64DW detection");
info->block_count = 2048;
break;
case MTC_W25Q32_BV:
NRF_LOG_INFO("W25Q32BV detection");
info->block_count = 1024;
break;
case MTC_W25Q32_DW:
NRF_LOG_INFO("W25Q32DW detection");
info->block_count = 1024;
break;
case MTC_W25Q16_BV_CL_CV:
NRF_LOG_INFO("W25Q16BV or W25Q16CL or W25Q16CV detection");
info->block_count = 512;
break;
case MTC_W25Q16_DW:
NRF_LOG_INFO("W25Q16DW detection");
info->block_count = 512;
break;
default:
NRF_LOG_INFO("Memory Capacity error! %d", memory_type_capacity);
info->block_count = 0;
return NRF_ERROR_INVALID_PARAM;
}
return NRF_SUCCESS;
}


ret_code_t hal_spi_flash_read(uint32_t address, void *buffer, size_t size) {

uint8_t tx[4];
Expand Down Expand Up @@ -241,7 +238,4 @@ ret_code_t hal_spi_flash_erase(uint32_t address) {
return NRF_SUCCESS;
}


void hal_spi_flash_sleep(){
hal_spi_flash_write_cmd(CMD_DP);
}
void hal_spi_flash_sleep() { hal_spi_flash_write_cmd(CMD_DP); }
7 changes: 3 additions & 4 deletions fw/application/src/mod/vfs/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stddef.h>
#include <stdint.h>

#include "boards_defines.h"
#include "boards.h"

// Virtual Object Storage

Expand Down Expand Up @@ -91,8 +91,7 @@ typedef struct {
int32_t (*close_file)(vfs_file_t *fd);
int32_t (*read_file)(vfs_file_t *fd, void *buff, size_t buff_size);
int32_t (*write_file)(vfs_file_t *fd, void *buff, size_t buff_size);
int32_t (*update_file_meta)(const char* file, void* meta, size_t meta_size);

int32_t (*update_file_meta)(const char *file, void *meta, size_t meta_size);

/**short opearation*/
int32_t (*write_file_data)(const char *file, void *buff, size_t buff_size);
Expand All @@ -105,7 +104,7 @@ typedef struct {

bool vfs_drive_enabled(vfs_drive_t drive);
vfs_driver_t *vfs_get_driver(vfs_drive_t drive);
vfs_driver_t* vfs_get_default_driver();
vfs_driver_t *vfs_get_default_driver();
vfs_drive_t vfs_get_default_drive();

#endif
54 changes: 27 additions & 27 deletions fw/application/src/mod/vfs/vfs_driver_lfs.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "boards_defines.h"
#include "boards.h"

#ifdef VFS_LFS_ENABLE
#include "vfs_driver_fs.h"
Expand Down Expand Up @@ -244,7 +244,7 @@ int32_t vfs_lfs_read_dir_internal(vfs_dir_t *fd, vfs_obj_t *obj) {

int32_t vfs_lfs_read_dir(vfs_dir_t *fd, vfs_obj_t *obj) {
int32_t err;
//skip . and .. directory
// skip . and .. directory
while ((err = vfs_lfs_read_dir_internal(fd, obj)) == VFS_OK) {
if (strcmp(obj->name, ".") != 0 && strcmp(obj->name, "..") != 0) {
return err;
Expand Down Expand Up @@ -395,29 +395,29 @@ int32_t vfs_lfs_remove_file(const char *file) {

// TODO
const vfs_driver_t vfs_driver_fs = {.mount = vfs_lfs_mount,
.umount = vfs_lfs_umount,
.format = vfs_lfs_format,
.mounted = vfs_lfs_mounted,
.stat = vfs_lfs_stat,

.stat_file = vfs_lfs_stat_file,

.open_dir = vfs_lfs_open_dir,
.read_dir = vfs_lfs_read_dir,
.close_dir = vfs_lfs_close_dir,
.create_dir = vfs_lfs_create_dir,
.remove_dir = vfs_lfs_remove_dir,
.rename_dir = vfs_lfs_rename_dir,

.open_file = vfs_lfs_open_file,
.close_file = vfs_lfs_close_file,
.read_file = vfs_lfs_read_file,
.write_file = vfs_lfs_write_file,
.update_file_meta = vfs_lfs_update_file_meta,

.write_file_data = vfs_lfs_write_file_data,
.read_file_data = vfs_lfs_read_file_data,

.rename_file = vfs_lfs_rename_file,
.remove_file = vfs_lfs_remove_file};
.umount = vfs_lfs_umount,
.format = vfs_lfs_format,
.mounted = vfs_lfs_mounted,
.stat = vfs_lfs_stat,

.stat_file = vfs_lfs_stat_file,

.open_dir = vfs_lfs_open_dir,
.read_dir = vfs_lfs_read_dir,
.close_dir = vfs_lfs_close_dir,
.create_dir = vfs_lfs_create_dir,
.remove_dir = vfs_lfs_remove_dir,
.rename_dir = vfs_lfs_rename_dir,

.open_file = vfs_lfs_open_file,
.close_file = vfs_lfs_close_file,
.read_file = vfs_lfs_read_file,
.write_file = vfs_lfs_write_file,
.update_file_meta = vfs_lfs_update_file_meta,

.write_file_data = vfs_lfs_write_file_data,
.read_file_data = vfs_lfs_read_file_data,

.rename_file = vfs_lfs_rename_file,
.remove_file = vfs_lfs_remove_file};
#endif
Loading

0 comments on commit a478552

Please sign in to comment.