Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/hal/si4707_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ struct Si4707_HAL_FPs {
void (*reset)();
void (*power_up)();
void (*send_command)(const uint8_t cmd, const struct Si4707_Command_Args* args);

void (*send_command_and_read_response)(const bool wait_for_cts_command, const uint8_t cmd, const struct Si4707_Command_Args* args,
const bool wait_for_cts_response, const uint8_t resp_length, uint8_t* resp_buf);
};

#endif // SI4707_HAL_H
45 changes: 41 additions & 4 deletions src/hal/si4707_hal_rp2040_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include "pico/stdlib.h"
#include "hardware/spi.h"

#include "si4707_const.h"
#include "si4707_hal.h"
#include "si4707.h"

spi_inst_t* g_hal_rp2040_spi = NULL;
uint g_hal_rp2040_mosi_pin = 0;
Expand Down Expand Up @@ -35,14 +37,16 @@ void hal_rp2040_set_si4707_pinmap(spi_inst_t *spi, uint mosi_pin, uint miso_pin,
g_hal_rp2040_pinmap_set = true;
}

void hal_rp2040_assert_pinmap_set() {
void hal_rp2040_assert_pinmap_set()
{
if (!g_hal_rp2040_pinmap_set) {
printf("RP2040 HAL: pinmap not set for Si4707 but you're trying to use it\n");
abort();
}
}

void hal_rp2040_setup_si4707_spi() {
void hal_rp2040_setup_si4707_spi()
{
hal_rp2040_assert_pinmap_set();

// SPI initialization. 400kHz.
Expand All @@ -57,7 +61,8 @@ void hal_rp2040_setup_si4707_spi() {
gpio_put(g_hal_rp2040_cs_pin, 1);
}

void hal_rp2040_prepare_interface() {
void hal_rp2040_prepare_interface()
{
hal_rp2040_setup_si4707_spi();
}

Expand Down Expand Up @@ -117,6 +122,38 @@ void hal_rp2040_si4707_reset()
sleep_ms(2);
}

void si4707_hal_rpi2040_spi_send_command_and_read_response(const bool wait_for_cts_command, const uint8_t cmd, const struct Si4707_Command_Args* args,
const bool wait_for_cts_response, const uint8_t resp_length, uint8_t* resp_buf)
{
// note to self: unclear whether i should use the
// HAL version or the driver version. kmo 17 jan 2024
// si4707_txn_start();
hal_rp2040_si4707_txn_start();

if (wait_for_cts_command) {
si4707_await_cts(CTS_WAIT);
}

uint8_t cmd_buf[9] = { 0x00 };
cmd_buf[0] = cmd;
cmd_buf[1] = args->ARG1; cmd_buf[2] = args->ARG2; cmd_buf[3] = args->ARG3;
cmd_buf[4] = args->ARG4; cmd_buf[5] = args->ARG5; cmd_buf[6] = args->ARG6;
cmd_buf[7] = args->ARG7;

// TODO: i cannot remember why this is 9 instead of 8 length
// kmo 17 jan 2024 20h50
spi_write_blocking(g_hal_rp2040_spi, cmd_buf, 9);

if (wait_for_cts_response) {
si4707_await_cts(CTS_WAIT);
}

spi_read_blocking(g_hal_rp2040_spi, 0, resp_buf, resp_length);

hal_rp2040_si4707_txn_end();

}

struct Si4707_HAL_FPs* hal_rp2040_FPs()
{
struct Si4707_HAL_FPs* function_pointers = (struct Si4707_HAL_FPs*)malloc(sizeof(struct Si4707_HAL_FPs));
Expand All @@ -127,4 +164,4 @@ struct Si4707_HAL_FPs* hal_rp2040_FPs()
function_pointers->reset = hal_rp2040_si4707_reset;

return function_pointers;
}
}
3 changes: 0 additions & 3 deletions src/si4707/si4707.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
#define MIN(a, b) ((b)>(a)?(a):(b))
#endif

#define CTS_WAIT 250


struct Si4707_HAL_FPs* current_hal = NULL;
void si4707_set_hal(struct Si4707_HAL_FPs* hal) {
current_hal = hal;
Expand Down
4 changes: 3 additions & 1 deletion src/si4707/si4707_const.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,6 @@
// see also HDRRDY (header ready)
#define SI4707_SAME_STATE_HEADER_COMPLETE 3

// TODO: this list of available properties is probably not complete. check AN332. kmo 9 oct 2023
// TODO: this list of available properties is probably not complete. check AN332. kmo 9 oct 2023

#define CTS_WAIT 250