Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added i2c buffer size to Wire interface #2292

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
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
1 change: 1 addition & 0 deletions hal/inc/hal_dynalib_i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ DYNALIB_FN(BASE_IDX + 18, hal_i2c, hal_i2c_lock, int32_t(hal_i2c_interface_t, vo
DYNALIB_FN(BASE_IDX + 19, hal_i2c, hal_i2c_unlock, int32_t(hal_i2c_interface_t, void*))
DYNALIB_FN(BASE_IDX + 20, hal_i2c, hal_i2c_request_ex, int32_t(hal_i2c_interface_t, const hal_i2c_transmission_config_t*, void*))
DYNALIB_FN(BASE_IDX + 21, hal_i2c, hal_i2c_sleep, int(hal_i2c_interface_t i2c, bool sleep, void* reserved))
DYNALIB_FN(BASE_IDX + 22, hal_i2c, hal_i2c_get_config, bool(hal_i2c_interface_t, hal_i2c_config_t*, void*))

DYNALIB_END(hal_i2c)

Expand Down
1 change: 1 addition & 0 deletions hal/inc/i2c_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ int32_t hal_i2c_available(hal_i2c_interface_t i2c, void* reserved);
int32_t hal_i2c_read(hal_i2c_interface_t i2c, void* reserved);
int32_t hal_i2c_peek(hal_i2c_interface_t i2c, void* reserved);
void hal_i2c_flush(hal_i2c_interface_t i2c, void* reserved);
bool hal_i2c_get_config(hal_i2c_interface_t i2c, hal_i2c_config_t* config, void* reserved);
bool hal_i2c_is_enabled(hal_i2c_interface_t i2c, void* reserved);
void hal_i2c_set_callback_on_received(hal_i2c_interface_t i2c, void (*function)(int), void* reserved);
void hal_i2c_set_callback_on_requested(hal_i2c_interface_t i2c, void (*function)(void), void* reserved);
Expand Down
11 changes: 11 additions & 0 deletions hal/src/nRF52840/i2c_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,17 @@ void hal_i2c_flush(hal_i2c_interface_t i2c, void* reserved) {
i2cMap[i2c].tx_index_tail = 0;
}

bool hal_i2c_get_config(hal_i2c_interface_t i2c, hal_i2c_config_t* config, void* reserved) {
if (i2c >= HAL_PLATFORM_I2C_NUM) {
return false;
}
config->rx_buffer = i2cMap[i2c].rx_buf;
config->rx_buffer_size = i2cMap[i2c].rx_buf_size;
config->tx_buffer = i2cMap[i2c].tx_buf;
config->tx_buffer_size = i2cMap[i2c].tx_buf_size;
return true;
}

bool hal_i2c_is_enabled(hal_i2c_interface_t i2c,void* reserved) {
return i2cMap[i2c].state == HAL_I2C_STATE_ENABLED;
}
Expand Down
8 changes: 8 additions & 0 deletions hal/src/stm32f2xx/i2c_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,14 @@ void hal_i2c_flush(hal_i2c_interface_t i2c, void* reserved) {
// XXX: to be implemented.
}

bool hal_i2c_get_config(hal_i2c_interface_t i2c, hal_i2c_config_t* config, void* reserved) {
config->rx_buffer = i2cMap[i2c]->rxBuffer;
config->rx_buffer_size = i2cMap[i2c]->rxBufferSize;
config->tx_buffer = i2cMap[i2c]->txBuffer;
config->tx_buffer_size = i2cMap[i2c]->txBufferSize;
return true;
}

bool hal_i2c_is_enabled(hal_i2c_interface_t i2c, void* reserved) {
return i2cMap[i2c]->state == HAL_I2C_STATE_ENABLED;
}
Expand Down
5 changes: 5 additions & 0 deletions hal/src/template/i2c_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ void hal_i2c_flush(hal_i2c_interface_t i2c,void* reserved)
// XXX: to be implemented.
}

bool hal_i2c_get_config(hal_i2c_interface_t i2c, hal_i2c_config_t* config, void* reserved)
{
return false;
}

bool hal_i2c_is_enabled(hal_i2c_interface_t i2c,void* reserved)
{
return false;
Expand Down
2 changes: 2 additions & 0 deletions wiring/inc/spark_wiring_i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ class TwoWire : public Stream
virtual int read(void);
virtual int peek(void);
virtual void flush(void);
size_t rxBufferSize(void);
size_t txBufferSize(void);
void onReceive(void (*)(int));
void onRequest(void (*)(void));

Expand Down
18 changes: 18 additions & 0 deletions wiring/src/spark_wiring_i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,24 @@ void TwoWire::flush(void)
hal_i2c_flush(_i2c, NULL);
}

size_t TwoWire::rxBufferSize(void)
{
hal_i2c_config_t config;
if (hal_i2c_get_config(_i2c, &config, NULL)) {
return config.rx_buffer_size;
}
return 0;
}

size_t TwoWire::txBufferSize(void)
{
hal_i2c_config_t config;
if (hal_i2c_get_config(_i2c, &config, NULL)) {
return config.tx_buffer_size;
}
return 0;
}

// sets function called on slave write
void TwoWire::onReceive( void (*function)(int) )
{
Expand Down