Merge pull request #1418 from openmv/add_cambus_enable

Add cambus_enable function.
This commit is contained in:
Ibrahim Abd Elkader 2021-07-31 22:23:03 +02:00 committed by GitHub
commit e8585ff226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 0 deletions

View File

@ -47,6 +47,7 @@ typedef struct _cambus {
int cambus_init(cambus_t *bus, uint32_t bus_id, uint32_t speed);
int cambus_deinit(cambus_t *bus);
int cambus_scan(cambus_t *bus);
int cambus_enable(cambus_t *bus, bool enable);
int cambus_gencall(cambus_t *bus, uint8_t cmd);
int cambus_pulse_scl(cambus_t *bus);
int cambus_readb(cambus_t *bus, uint8_t slv_addr, uint8_t reg_addr, uint8_t *reg_data);

View File

@ -137,6 +137,9 @@ __weak int sensor_reset()
// Restore shutdown state on reset.
sensor_shutdown(false);
// Disable the bus before reset.
cambus_enable(&sensor.bus, false);
// Hard-reset the sensor
if (sensor.reset_pol == ACTIVE_HIGH) {
DCMI_RESET_HIGH();
@ -150,6 +153,9 @@ __weak int sensor_reset()
mp_hal_delay_ms(20);
// Re-enable the bus.
cambus_enable(&sensor.bus, true);
// Check if the control is supported.
if (sensor.reset == NULL) {
return SENSOR_ERROR_CTL_UNSUPPORTED;

View File

@ -97,6 +97,18 @@ int cambus_scan(cambus_t *bus)
return 0;
}
int cambus_enable(cambus_t *bus, bool enable)
{
if (bus->initialized) {
if (enable) {
nrfx_twi_enable(&bus->i2c);
} else {
nrfx_twi_disable(&bus->i2c);
}
}
return 0;
}
int cambus_gencall(cambus_t *bus, uint8_t cmd)
{
uint32_t xfer_flags = 0;

View File

@ -74,6 +74,11 @@ int cambus_scan(cambus_t *bus)
return 0;
}
int cambus_enable(cambus_t *bus, bool enable)
{
return 0;
}
int cambus_readb(cambus_t *bus, uint8_t slv_addr, uint8_t reg_addr, uint8_t *reg_data)
{
int bytes = 0;

View File

@ -278,6 +278,18 @@ int cambus_scan(cambus_t *bus)
return 0;
}
int cambus_enable(cambus_t *bus, bool enable)
{
if (bus->initialized) {
if (enable) {
__HAL_I2C_ENABLE(bus->i2c);
} else {
__HAL_I2C_DISABLE(bus->i2c);
}
}
return 0;
}
int cambus_gencall(cambus_t *bus, uint8_t cmd)
{
if (HAL_I2C_Master_Transmit(bus->i2c, 0x00, &cmd, 1, I2C_TIMEOUT) != HAL_OK) {