Ejemplo n.º 1
0
void pin_config (pin_obj_t *self, uint af, uint mode, uint type, uint strength) {
    // configure the pin in analog mode
    self->af = af, self->mode = mode, self->type = type, self->strength = strength;
    pin_obj_configure ((const pin_obj_t *)self);
    // mark the pin as used
    self->isused = true;
    // register it with the sleep module
    pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pin_obj_configure);
}
Ejemplo n.º 2
0
/// \classmethod \constructor(channel)
/// Create an ADC object associated with the given channel.
/// This allows you to then read analog values on that pin.
STATIC mp_obj_t adc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
    // check number of arguments
    mp_arg_check_num(n_args, n_kw, 1, 1, false);

    // the first argument is the channel number
    int32_t idx = mp_obj_get_int(args[0]) - 1;
    const pin_obj_t *pin;
    uint channel;
    switch (idx) {
    case 0:
        channel = ADC_CH_0;
        pin = &pin_GP2;
        break;
    case 1:
        channel = ADC_CH_1;
        pin = &pin_GP3;
        break;
    case 2:
        channel = ADC_CH_2;
        pin = &pin_GP4;
        break;
    case 3:
        channel = ADC_CH_3;
        pin = &pin_GP5;
        break;
    default:
        nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
        break;
    }

    // disable the callback before re-configuring
    pyb_adc_obj_t *self = &pyb_adc_obj[idx];
    self->base.type = &pyb_adc_type;
    self->channel = channel;
    self->idx = idx;

    // configure the pin in analog mode
    pin_config ((pin_obj_t *)pin, PIN_MODE_0, GPIO_DIR_MODE_IN, PYBPIN_ANALOG_TYPE, PIN_STRENGTH_2MA);

    // initialize it
    pybadc_init (self);

    // register it with the sleep module
    pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pybadc_init);

    return self;
}
Ejemplo n.º 3
0
/// \classmethod \constructor(pin)
/// Create an ADC object associated with the given pin.
/// This allows you to then read analog values on that pin.
STATIC mp_obj_t adc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
    // check number of arguments
    mp_arg_check_num(n_args, n_kw, 1, 1, false);

    // the argument passed is the pin
    const pin_obj_t *pin = (pin_obj_t *)pin_find(args[0]);
    for (int32_t idx = 0; idx < PYB_ADC_NUM_CHANNELS; idx++) {
        if (pin == pyb_adc_obj[idx].pin) {
            pyb_adc_obj_t *self = &pyb_adc_obj[idx];
            self->base.type = &pyb_adc_type;
            pybadc_init (self);
            // register it with the sleep module
            pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pybadc_init);
            return self;
        }
    }
    nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments));
}
Ejemplo n.º 4
0
void pin_config (pin_obj_t *self, int af, uint mode, uint pull, int value, uint strength) {
    self->mode = mode, self->pull = pull, self->strength = strength;
    // if af is -1, then we want to keep it as it is
    if (af != -1) {
        self->af = af;
    }

    // if value is -1, then we want to keep it as it is
    if (value != -1) {
        self->value = value;
    }

    // mark the pin as used
    self->used = true;
    pin_obj_configure ((const pin_obj_t *)self);

    // register it with the sleep module
    pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pin_obj_configure);
}