예제 #1
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;
}
예제 #2
0
파일: main.c 프로젝트: arthurwolf/libmanyuc
/* This example turns all 4 leds on and then off */
int main(void) {

    // Access 4 leds predefined as LED1, LED2, LED3, LED4
    Pin_t leds[] = {
        Pin_Init(LED1, 1, Output),
        Pin_Init(LED2, 1, Output),
        Pin_Init(LED3, 1, Output),
    };
    int nleds = 3;

    Pin_t button = Pin_Init(SW1, 1, Output);
    Pin_Input(button),
    Pin_Mode(button, PullUp);

    // Get the sensor enabler
    Pin_t enabler = Pin_Init(LED_EN, 1, Output);
    Pin_Output(enabler),
    Pin_On(enabler);

    // Get AnalogIns
    uint32_t sensors[] = {
        AnalogIn_Get(SENS0),
        AnalogIn_Get(SENS1),
        AnalogIn_Get(SENS2),
        AnalogIn_Get(SENS3),
        AnalogIn_Get(SENS4) };
    int nsensors = 5;

    while (1) {
        if (Pin_Read(button) == SW_ON) {
            Pin_Off(leds[2]);
        } else {
            Pin_On(leds[2]);
        }
        if (AnalogIn_Read(sensors[0]) > 0) {
            Pin_Off(leds[1]);
        } else {
            Pin_On(leds[1]);
        }


/*      for (i = 0; i < nleds; i++) {
            Pin_On(leds[i]);
            Delay(0.2);
        }
        for (i = 0; i < nleds; i++) {
            Pin_Off(leds[i]);
            Delay(0.2);
        }*/
    }
}
예제 #3
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;
}