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

cpu/lpc2387: implement periph/i2c #13037

Merged
merged 4 commits into from
Feb 27, 2020
Merged
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 boards/mcb2388/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CPU_MODEL = lpc2388

# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_adc
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_rtc
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_timer
Expand Down
27 changes: 27 additions & 0 deletions boards/mcb2388/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,33 @@ static const adc_conf_t adc_config[] = {
};

#define ADC_NUMOF (1)

/**
* @name I2C configuration
* @{
*/
static const i2c_conf_t i2c_config[] = {
{
.dev = I2C0,
.speed = I2C_SPEED_NORMAL,
.irq_prio = 5,
.pinsel_sda = 1,
.pinsel_scl = 1,
.pinsel_msk_sda = BIT22, /* P0.27 */
.pinsel_msk_scl = BIT24, /* P0.28 */
},
{
.dev = I2C1,
.speed = I2C_SPEED_NORMAL,
.irq_prio = 5,
.pinsel_sda = 1,
.pinsel_scl = 1,
.pinsel_msk_sda = BIT6 | BIT7, /* P0.19 */
.pinsel_msk_scl = BIT8 | BIT9, /* P0.20 */
},
};

#define I2C_NUMOF (2)
/** @} */

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions boards/msba2/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CPU = lpc2387

# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_adc
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_pwm
FEATURES_PROVIDED += periph_rtc
FEATURES_PROVIDED += periph_spi
Expand Down
19 changes: 19 additions & 0 deletions boards/msba2/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,25 @@ static const adc_conf_t adc_config[] = {
#define ADC_NUMOF ARRAY_SIZE(adc_config)
/** @} */

/**
* @name I2C configuration
* @{
*/
static const i2c_conf_t i2c_config[] = {
{ /* JP3 */
.dev = I2C2,
.speed = I2C_SPEED_NORMAL,
.irq_prio = 5,
.pinsel_sda = 0,
.pinsel_scl = 0,
.pinsel_msk_sda = BIT21, /* P0.10 */
.pinsel_msk_scl = BIT23, /* P0.11 */
},
};

/* used in arithmetic preprocessor expression, so no ARRAY_SIZE() */
#define I2C_NUMOF (1)
maribu marked this conversation as resolved.
Show resolved Hide resolved
/** @} */

#ifdef __cplusplus
}
Expand Down
33 changes: 33 additions & 0 deletions cpu/lpc2387/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,40 @@ typedef struct {
uint32_t pinsel_msk; /**< PINSEL Mask for ADC pin */
} adc_conf_t;

/**
* @brief Override I2C clock speed values
* @{
*/
#define HAVE_I2C_SPEED_T
typedef enum {
I2C_SPEED_LOW = 10000, /**< low speed mode: ~10 kbit/s */
I2C_SPEED_NORMAL = 100000, /**< normal mode: ~100 kbit/s */
I2C_SPEED_FAST = 400000, /**< fast mode: ~400 kbit/s */
} i2c_speed_t;
/* @} */

/**
* @brief I2C device configuration
*/
typedef struct {
lpc23xx_i2c_t *dev; /**< pointer to the I2C device */
i2c_speed_t speed; /**< I2C bus speed */
uint8_t irq_prio; /**< priority of the I2C IRQ */
uint8_t pinsel_sda; /**< PINSEL# of the SDA pin */
uint8_t pinsel_scl; /**< PINSEL# of the SCL pin */
uint32_t pinsel_msk_sda;/**< SDA PINSEL Mask */
uint32_t pinsel_msk_scl;/**< SCL PINSEL Mask */
} i2c_conf_t;
/* @} */

/**
* @name Use shared I2C functions
* @{
*/
#define PERIPH_I2C_NEED_READ_REG
#define PERIPH_I2C_NEED_WRITE_REG
/** @} */

#ifdef __cplusplus
}
#endif
Expand Down
29 changes: 29 additions & 0 deletions cpu/lpc2387/include/vendor/lpc23xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,35 @@ typedef struct {
#define U3FDR (*(volatile unsigned long *)(UART3_BASE_ADDR + 0x28))
#define U3TER (*(volatile unsigned long *)(UART3_BASE_ADDR + 0x30))

/**
* @brief Generic I2C register map
*/
typedef struct {
REG32 CONSET; /**< Control Set Register */
REG32 STAT; /**< Status Register */
REG32 DAT; /**< Data Register */
REG32 ADR; /**< Slave Address Register */
REG32 SCLH; /**< Duty Cycle High Half Word */
REG32 SCLL; /**< Duty Cycle Low Half Word */
REG32 CONCLR; /**< Control Clear Register */
} lpc23xx_i2c_t;

/* I2C Control Set Register */
#define I2CONSET_AA 0x00000004 /**< Assert acknowledge */
#define I2CONSET_SI 0x00000008 /**< Interrupt flag */
#define I2CONSET_STO 0x00000010 /**< STOP flag */
#define I2CONSET_STA 0x00000020 /**< START flag */
#define I2CONSET_I2EN 0x00000040 /**< Interface enable */

/* I2C Control clear Register */
#define I2CONCLR_AAC 0x00000004 /**< clear Assert ACK */
#define I2CONCLR_SIC 0x00000008 /**< clear Interrupt */
#define I2CONCLR_STAC 0x00000020 /**< clear START flag */
#define I2CONCLR_I2ENC 0x00000040 /**< Interface disable */

/* I2C Interface 0 */
#define I2C0_BASE_ADDR 0xE001C000
#define I2C0 ((lpc23xx_i2c_t *)I2C0_BASE_ADDR)
#define I20CONSET (*(volatile unsigned long *)(I2C0_BASE_ADDR + 0x00))
#define I20STAT (*(volatile unsigned long *)(I2C0_BASE_ADDR + 0x04))
#define I20DAT (*(volatile unsigned long *)(I2C0_BASE_ADDR + 0x08))
Expand All @@ -783,6 +810,7 @@ typedef struct {

/* I2C Interface 1 */
#define I2C1_BASE_ADDR 0xE005C000
#define I2C1 ((lpc23xx_i2c_t *)I2C1_BASE_ADDR)
#define I21CONSET (*(volatile unsigned long *)(I2C1_BASE_ADDR + 0x00))
#define I21STAT (*(volatile unsigned long *)(I2C1_BASE_ADDR + 0x04))
#define I21DAT (*(volatile unsigned long *)(I2C1_BASE_ADDR + 0x08))
Expand All @@ -793,6 +821,7 @@ typedef struct {

/* I2C Interface 2 */
#define I2C2_BASE_ADDR 0xE0080000
#define I2C2 ((lpc23xx_i2c_t *)I2C2_BASE_ADDR)
#define I22CONSET (*(volatile unsigned long *)(I2C2_BASE_ADDR + 0x00))
#define I22STAT (*(volatile unsigned long *)(I2C2_BASE_ADDR + 0x04))
#define I22DAT (*(volatile unsigned long *)(I2C2_BASE_ADDR + 0x08))
Expand Down
Loading