mirror of https://github.com/ARMmbed/mbed-os.git
I2C, pullup
parent
c9a029ce6f
commit
b73b57db26
|
|
@ -45,7 +45,6 @@ typedef enum {
|
|||
PWM_6 = (0 << TPM_SHIFT) | (5), // FTM0 CH5
|
||||
PWM_7 = (0 << TPM_SHIFT) | (6), // FTM0 CH6
|
||||
PWM_8 = (0 << TPM_SHIFT) | (7), // FTM0 CH7
|
||||
|
||||
PWM_9 = (1 << TPM_SHIFT) | (0), // FTM1 CH0
|
||||
PWM_10 = (1 << TPM_SHIFT) | (1), // FTM1 CH1
|
||||
} PWMName;
|
||||
|
|
|
|||
|
|
@ -235,10 +235,11 @@ typedef enum {
|
|||
NC = (int)0xFFFFFFFF
|
||||
} PinName;
|
||||
|
||||
/* PullDown not available for KL05 */
|
||||
|
||||
typedef enum {
|
||||
PullNone = 0,
|
||||
PullUp = 2,
|
||||
PullDown = 2,
|
||||
PullUp = 3,
|
||||
} PinMode;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -31,4 +31,5 @@ typedef enum {
|
|||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -20,25 +20,14 @@
|
|||
#include "error.h"
|
||||
|
||||
static const PinMap PinMap_I2C_SDA[] = {
|
||||
{PTE25, I2C_0, 5},
|
||||
{PTC9, I2C_0, 2},
|
||||
{PTE0, I2C_0, 6},
|
||||
{PTB1, I2C_0, 2},
|
||||
{PTB3, I2C_0, 2},
|
||||
{PTC11, I2C_0, 2},
|
||||
{PTC2, I2C_0, 2},
|
||||
{PTA4, I2C_0, 2},
|
||||
{NC , NC , 0}
|
||||
};
|
||||
|
||||
static const PinMap PinMap_I2C_SCL[] = {
|
||||
{PTE24, I2C_0, 5},
|
||||
{PTC8, I2C_0, 2},
|
||||
{PTE1, I2C_0, 6},
|
||||
{PTB0, I2C_0, 2},
|
||||
{PTB2, I2C_0, 2},
|
||||
{PTC10, I2C_0, 2},
|
||||
{PTC1, I2C_0, 2},
|
||||
{NC , NC, 0}
|
||||
};
|
||||
|
||||
|
|
@ -66,15 +55,11 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
|||
I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
|
||||
I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
|
||||
obj->i2c = (I2C_Type*)pinmap_merge(i2c_sda, i2c_scl);
|
||||
if ((int)obj->i2c == NC) {
|
||||
if ((int)obj->i2c == NC)
|
||||
error("I2C pin mapping failed");
|
||||
}
|
||||
|
||||
// enable power
|
||||
switch ((int)obj->i2c) {
|
||||
case I2C_0: SIM->SCGC5 |= 1 << 13; SIM->SCGC4 |= 1 << 6; break;
|
||||
//case I2C_1: SIM->SCGC5 |= 1 << 11; SIM->SCGC4 |= 1 << 7; break;
|
||||
}
|
||||
SIM->SCGC4 |= SIM_SCGC4_I2C0_MASK;
|
||||
SIM->SCGC5 |= SIM_SCGC5_PORTB_MASK;
|
||||
|
||||
// set default frequency at 100k
|
||||
i2c_frequency(obj, 100000);
|
||||
|
|
@ -89,7 +74,7 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
|
|||
}
|
||||
|
||||
int i2c_start(i2c_t *obj) {
|
||||
uint8_t temp;
|
||||
uint32_t temp;
|
||||
volatile int i;
|
||||
// if we are in the middle of a transaction
|
||||
// activate the repeat_start flag
|
||||
|
|
@ -118,7 +103,8 @@ int i2c_stop(i2c_t *obj) {
|
|||
// when there is no waiting time after a STOP.
|
||||
// This wait is also included on the samples
|
||||
// code provided with the freedom board
|
||||
for (n = 0; n < 100; n++) __NOP();
|
||||
for (n = 0; n < 100; n++)
|
||||
__NOP();
|
||||
first_read = 1;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@
|
|||
#include "error.h"
|
||||
|
||||
void pin_function(PinName pin, int function) {
|
||||
if (pin == (PinName)NC) return;
|
||||
if (pin == (PinName)NC)
|
||||
return;
|
||||
|
||||
uint32_t port_n = (uint32_t)pin >> PORT_SHIFT;
|
||||
uint32_t pin_n = (uint32_t)(pin & 0x7C) >> 2;
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ void rtc_init(void) {
|
|||
init();
|
||||
|
||||
// Enable the oscillator
|
||||
RTC_CR |= RTC_CR_OSCE_MASK;
|
||||
RTC->CR |= RTC_CR_OSCE_MASK;
|
||||
|
||||
//Configure the TSR. default value: 1
|
||||
RTC->TSR = 1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue