/*----------------------------------------------------------------------------*/ void pinSetPull(struct Pin pin, enum PinPull pull) { volatile uint32_t * const reg = calcPinMode(pin.data); uint32_t value = *reg & ~PIN_OFFSET(PIN_MASK, pin.data.offset); switch (pull) { case PIN_NOPULL: value |= PIN_OFFSET(PIN_MODE_INACTIVE, pin.data.offset); break; case PIN_PULLUP: value |= PIN_OFFSET(PIN_MODE_PULLUP, pin.data.offset); break; case PIN_PULLDOWN: value |= PIN_OFFSET(PIN_MODE_PULLDOWN, pin.data.offset); break; } *reg = value; }
/*----------------------------------------------------------------------------*/ void pinSetFunction(struct Pin pin, uint8_t function) { /* Function should not be used outside platform drivers */ switch (function) { case PIN_DEFAULT: function = 0; /* Zero function is the default for all pins */ break; case PIN_ANALOG: return; } volatile uint32_t * const reg = calcPinSelect(pin.data); uint32_t value = *reg & ~PIN_OFFSET(PIN_MASK, pin.data.offset); value |= PIN_OFFSET(function, pin.data.offset); *reg = value; }
int gpio_read(int const pin_nr) { assert(gpio != NULL); return GPLEV[PIN_OFFSET(pin_nr)] & PIN_VAL(pin_nr); }