Skip to content
Snippets Groups Projects
Commit 88122612 authored by schneider's avatar schneider
Browse files

feat(lib/card10): Initial port expander support

parent 6346e241
No related branches found
No related tags found
No related merge requests found
#include "pmic.h"
#include "bosch.h"
#include "display.h"
#include "portexpander.h"
#include "bhy_uc_driver.h"
#include "Bosch_PCB_7183_di03_BMI160_BMM150-7183_di03.2.1.11696_170103.h"
......@@ -92,6 +93,8 @@ void card10_init(void)
float sic_array[9] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
bhy_set_sic_matrix(sic_array);
}
portexpander_init();
}
static uint32_t ecg_read_reg(uint8_t reg)
......
......@@ -7,6 +7,7 @@ sources = files(
'card10.c',
'leds.c',
'pmic.c',
'portexpander.c',
)
deps = [
......
#include "portexpander.h"
#include "i2c.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
void portexpander_init(void)
{
uint8_t addr = 0x21;
// Enable pull-ups for buttons
uint8_t command[] = {0x43, 0x68};
I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, command, 2, 0);
// Set _all_ outputs to open-drain to support the high side p-channel transistors.
command[0] = 0x4F; command[1] = 0x01;
I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, command, 2, 0);
// Enable outputs for transistors and the LED
command[0] = 0x03; command[1] = 0x68;
I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, command, 2, 0);
// Set outputs to high (i.e. open-drain)
command[0] = 0x01; command[1] = 0x97;
I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, command, 2, 0);
}
uint8_t portexpander_get(void)
{
uint8_t addr = 0x21;
uint8_t command[] = {0x00};
I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, command, 1, 1);
uint8_t buf;
I2C_MasterRead(MXC_I2C1_BUS0, addr << 1, &buf, 1, 0);
return buf;
}
#ifndef PORTEXPANDER_H
#define PORTEXPANDER_H
#include <stdint.h>
void portexpander_init(void);
uint8_t portexpander_get(void);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment