drivers: mfd: mfd_npm1300: Added timer configuration function
Timer configuration function added Signed-off-by: Andy Sinclair <andy.sinclair@nordicsemi.no>
This commit is contained in:
parent
81c584e3e7
commit
c793764549
2 changed files with 43 additions and 2 deletions
|
|
@ -9,8 +9,17 @@
|
|||
|
||||
#include <zephyr/drivers/i2c.h>
|
||||
#include <zephyr/sys/util.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
#include <zephyr/drivers/mfd/npm1300.h>
|
||||
|
||||
#define TIME_BASE 0x07U
|
||||
|
||||
#define TIME_OFFSET_LOAD 0x03U
|
||||
#define TIME_OFFSET_TIMER 0x08U
|
||||
|
||||
#define TIMER_PRESCALER_MS 16U
|
||||
#define TIMER_MAX 0xFFFFFFU
|
||||
|
||||
struct mfd_npm1300_config {
|
||||
struct i2c_dt_spec i2c;
|
||||
};
|
||||
|
|
@ -85,6 +94,27 @@ int mfd_npm1300_reg_update(const struct device *dev, uint8_t base, uint8_t offse
|
|||
return ret;
|
||||
}
|
||||
|
||||
int mfd_npm1300_set_timer(const struct device *dev, uint32_t time_ms)
|
||||
{
|
||||
const struct mfd_npm1300_config *config = dev->config;
|
||||
uint8_t buff[5] = {TIME_BASE, TIME_OFFSET_TIMER};
|
||||
uint32_t ticks = time_ms / TIMER_PRESCALER_MS;
|
||||
|
||||
if (ticks > TIMER_MAX) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
sys_put_be24(ticks, &buff[2]);
|
||||
|
||||
int ret = i2c_write_dt(&config->i2c, buff, sizeof(buff));
|
||||
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return mfd_npm1300_reg_write(dev, TIME_BASE, TIME_OFFSET_LOAD, 1U);
|
||||
}
|
||||
|
||||
#define MFD_NPM1300_DEFINE(inst) \
|
||||
static struct mfd_npm1300_data data_##inst; \
|
||||
\
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ extern "C" {
|
|||
* @retval 0 If successful
|
||||
* @retval -errno In case of any bus error (see i2c_write_read_dt())
|
||||
*/
|
||||
int mfd_npm1300_reg_read_burst(const struct device *dev, uint8_t base, uint8_t offset,
|
||||
void *data, size_t len);
|
||||
int mfd_npm1300_reg_read_burst(const struct device *dev, uint8_t base, uint8_t offset, void *data,
|
||||
size_t len);
|
||||
|
||||
/**
|
||||
* @brief Read single register from npm1300
|
||||
|
|
@ -87,6 +87,17 @@ int mfd_npm1300_reg_write2(const struct device *dev, uint8_t base, uint8_t offse
|
|||
int mfd_npm1300_reg_update(const struct device *dev, uint8_t base, uint8_t offset, uint8_t data,
|
||||
uint8_t mask);
|
||||
|
||||
/**
|
||||
* @brief Write npm1300 timer register
|
||||
*
|
||||
* @param dev npm1300 mfd device
|
||||
* @param time_ms timer value in ms
|
||||
* @retval 0 If successful
|
||||
* @retval -EINVAL if time value is too large
|
||||
* @retval -errno In case of any bus error (see i2c_write_dt())
|
||||
*/
|
||||
int mfd_npm1300_set_timer(const struct device *dev, uint32_t time_ms);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
Loading…
Reference in a new issue