Added LED.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Yilin Sun <imi415@imi.moe>
This commit is contained in:
parent
79a5b1fc18
commit
43cad6e5fe
|
@ -11,6 +11,7 @@ typedef struct {
|
|||
i2c_inst_t *i2c_inst;
|
||||
uint8_t scl_pin;
|
||||
uint8_t sda_pin;
|
||||
uint8_t led_pin;
|
||||
|
||||
/* Peripheral Specific */
|
||||
uint8_t dev_addr;
|
||||
|
|
|
@ -15,12 +15,19 @@ int app_sensors_impl_init(void *pdev) {
|
|||
gpio_pull_up(impl->sda_pin);
|
||||
gpio_pull_up(impl->scl_pin);
|
||||
|
||||
if (impl->led_pin != 0xFF) {
|
||||
gpio_init(impl->led_pin);
|
||||
gpio_set_dir(impl->led_pin, GPIO_OUT);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ims_ret_t app_sensors_i2c_xfer(void *pdev, ims_i2c_xfer_desc_t *xfer) {
|
||||
app_sensors_impl_t *impl = pdev;
|
||||
|
||||
gpio_put(impl->led_pin, 1U);
|
||||
|
||||
if (xfer->tx_data) {
|
||||
bool no_stop = false;
|
||||
|
||||
|
@ -29,7 +36,6 @@ ims_ret_t app_sensors_i2c_xfer(void *pdev, ims_i2c_xfer_desc_t *xfer) {
|
|||
}
|
||||
|
||||
int ret = i2c_write_blocking(impl->i2c_inst, impl->dev_addr, xfer->tx_data, xfer->tx_size, no_stop);
|
||||
|
||||
if (ret != xfer->tx_size) {
|
||||
return IMS_FAIL;
|
||||
}
|
||||
|
@ -37,12 +43,13 @@ ims_ret_t app_sensors_i2c_xfer(void *pdev, ims_i2c_xfer_desc_t *xfer) {
|
|||
|
||||
if (xfer->rx_data) {
|
||||
int ret = i2c_read_blocking(impl->i2c_inst, impl->dev_addr, xfer->rx_data, xfer->rx_size, false);
|
||||
|
||||
if (ret != xfer->rx_size) {
|
||||
return IMS_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
gpio_put(impl->led_pin, 0U);
|
||||
|
||||
return IMS_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ static app_sensors_impl_t s_sensor_impl = {
|
|||
.i2c_inst = APP_SENSORS_I2C_INST,
|
||||
.sda_pin = APP_SENSORS_I2C_SDA_PIN,
|
||||
.scl_pin = APP_SENSORS_I2C_SCL_PIN,
|
||||
.led_pin = PICO_DEFAULT_LED_PIN,
|
||||
|
||||
.dev_addr = 0x02U,
|
||||
};
|
||||
|
@ -56,8 +57,10 @@ int main(void) {
|
|||
uint8_t irq_status;
|
||||
ims_as3935_get_irq_status(&s_ltn, &irq_status);
|
||||
|
||||
printf("[%8ld] ", to_ms_since_boot(get_absolute_time()));
|
||||
|
||||
if (irq_status & IMS_AS3935_IRQ_TYPE_NH) {
|
||||
printf("Noise level too high, increasing threshold...\r\n");
|
||||
printf("Noise level too high...\r\n");
|
||||
uint8_t nf;
|
||||
|
||||
ims_as3935_get_noise_floor(&s_ltn, &nf);
|
||||
|
|
Loading…
Reference in New Issue