예제 #1
0
파일: i2c.c 프로젝트: arthurwolf/libmanyuc
I2C_t I2C_Init(uint8_t port, uint8_t address, I2CMode mode) {
    if (port > 2) Show_Error();

    Pin_t sda = Pin_Get(sdas[port]);
    Pin_t scl = Pin_Get(scls[port]);

    // Set function
    Pin_Mode(sda, modes[port]);
    Pin_Mode(scl, modes[port]);

    // Set input mode
    Pin_Mode(sda, PullNone);
    Pin_Mode(scl, PullNone);
    Pin_Mode(sda, OpenDrain);
    Pin_Mode(scl, OpenDrain);

    // Give power to the device
    LPC_SC->PCONP |= (uint32_t)(1 << power_bit[port]);

    // Store initialization values
    if (mode == I2CMaster) {
        _set_clock(port, 100000);
    } else {
        i2c_devs[port]->I2ADR0 = (uint32_t) address;
    }

    // Enable
    //i2c_devs[port]->I2CONSET = I2C_I2CONSET_I2EN;
    i2c_devs[port]->I2CONSET = I2C_I2CONSET_I2EN | I2C_I2CONSET_AA;
    //i2c_devs[port]->I2CONCLR = (I2C_I2CONCLR_STOC | I2C_I2CONCLR_STAC | I2C_I2CONCLR_SIC | I2C_I2CONCLR_AAC);
    // Clear Stop, Start, SI
    i2c_devs[port]->I2CONCLR = (I2C_I2CONCLR_STOC | I2C_I2CONCLR_STAC | I2C_I2CONCLR_SIC );
    
    uint8_t state = i2c_devs[port]->I2CONSET;

    // Return the I2C device
    I2C_t device = { port, address, mode };
    return device;
}
예제 #2
0
파일: adc.c 프로젝트: bgamari/libmanyuc
AnalogIn_t AnalogIn_Init(PinName pin_name) {

    // Check if the global initialization is needed.
    if (!(PMC->PMC_PCER0 & ADC_POWER_BITMASK)) {
        ADC_Init();
    }

    AnalogIn_t analog_in = AnalogIn_Get(pin_name);

    // Set the pin bit function
    Pin_t pin = Pin_Get(pin_name);
    Pin_Input(pin);
    Pin_Mode(pin, PullNone);
    Pin_Mode(pin, PD);

    return analog_in;
}
예제 #3
0
Bus::Bus(int nmodes, ... ) {

    // Get the pinBus
    va_list pins;
    va_start(pins, npins);
    this->bus.pinBus = vPinBus_Get(npins, pins);
    this->bus.npins = npins;
    va_end(pins);

    // Get all the pins
    va_start(pins, npins);
    this->bus.pins = malloc(sizeof(Pin_t) * npins);
    int i;
    for (i = 0; i < npins; i++) {
        this->bus.pins[i] = Pin_Get(va_arg(pins, uint32_t));
    }
    va_end(pins);

}