void pinMode(uint8_t pin, uint8_t mode){ GPFSEL(pin) &= ~(0x07 << GPFSELB(pin));//clear gpio function GPFSEL(pin) |= ((mode & 0x07) << GPFSELB(pin));//set function to pin if((mode & 0x07) == 0){//PULLUP/PULLDOWN mode &= 0x30; mode >>= 4; GPPUD = mode; delay(0.01); if(pin < 32) GPPUDCLK0 = _BV(pin); else if(pin < 46) GPPUDCLK1 = _BV(pin - 32); delay(0.01); GPPUD = 0; if(pin < 32) GPPUDCLK0 = 0; else if(pin < 46) GPPUDCLK1 = 0; }
void pin_mode(PinName pin, PinMode mode) { if (pin == (PinName)NC) { return; } // set pullup, pulldown,... // select resister number int group = pin / 10; vuint32_t *res = GPFSEL(group); vuint32_t shift = (pin % 10) * 3; switch(mode){ case Output: case Alt0: case Alt1: case Alt2: case Alt3: case Alt4: case Alt5: *res = (mode << shift) | (*res & ~(0x07 << shift)); break; case PullUp: case PullDown: case PullNone: pin_pull(pin, mode); break; case Input: // register clear(3bit) *res &= ~(0x07 << shift); default: return; } }