void LCD4Bit_mod::home(){ clrbits(CONTROL_PORT, CONTROL_RS); #ifdef USING_RW clrbits(CONTROL_PORT, CONTROL_RW); #endif pushByte(CMD_HOME); delayMicroseconds(1640); // 1.64ms }
void LCD4Bit_mod::commandWriteNibble(uint8_t nibble) { clrbits(CONTROL_PORT, CONTROL_RS); #ifdef USING_RW clrbits(CONTROL_PORT, CONTROL_RW); #endif pushNibble(nibble); delayMicroseconds(40); // commands need > 37us to settle }
/* * Copy clist to buffer. * Return number of bytes moved. */ int q_to_b(struct clist *clp, u_char *cp, int count) { int cc; u_char *p = cp; int s; s = spltty(); /* optimize this while loop */ while (count > 0 && clp->c_cc > 0) { cc = clp->c_cl - clp->c_cf; if (clp->c_cf >= clp->c_cl) cc = clp->c_ce - clp->c_cf; if (cc > count) cc = count; bcopy(clp->c_cf, p, cc); memset(clp->c_cf, 0, cc); if (clp->c_cq) clrbits(clp->c_cq, clp->c_cf - clp->c_cs, cc); count -= cc; p += cc; clp->c_cc -= cc; clp->c_cf += cc; if (clp->c_cf == clp->c_ce) clp->c_cf = clp->c_cs; } if (clp->c_cc == 0) clp->c_cf = clp->c_cl = (u_char *)0; splx(s); return p - cp; }
//pulse the Enable pin high (for a microsecond). //This clocks whatever command or data is in DB4~7 into the LCD controller. void LCD4Bit_mod::pulseEnablePin(){ //clrbits(CONTROL_PORT, CONTROL_EN); //digitalWrite(Enable,LOW); //delayMicroseconds(1); // send a pulse to enable setbits(CONTROL_PORT, CONTROL_EN); //digitalWrite(Enable,HIGH); delayMicroseconds(1); // enable pulse must be >450ns clrbits(CONTROL_PORT, CONTROL_EN); //digitalWrite(Enable,LOW); //delayMicroseconds(40); // commands need > 37us to settle }
//print the given character at the current cursor position. overwrites, doesn't insert. void LCD4Bit_mod::print(uint8_t value) { //set the RS and RW pins to show we're writing data setbits(CONTROL_PORT, CONTROL_RS);//digitalWrite(RS, HIGH); #ifdef USING_RW clrbits(CONTROL_PORT, CONTROL_RW);//digitalWrite(RW, LOW); #endif //let pushByte worry about the intricacies of Enable, nibble order. pushByte(value); delayMicroseconds(40); // commands need > 37us to settle }
//print the given string to the LCD at the current cursor position. overwrites, doesn't insert. //While I don't understand why this was named printIn (PRINT IN?) in the original LiquidCrystal library, I've preserved it here to maintain the interchangeability of the two libraries. void LCD4Bit_mod::printIn(const char* msg) { setbits(CONTROL_PORT, CONTROL_RS);//digitalWrite(RS, HIGH); #ifdef USING_RW clrbits(CONTROL_PORT, CONTROL_RW);//digitalWrite(RW, LOW); #endif uint8_t i; //fancy int. avoids compiler warning when comparing i with strlen()'s uint8_t uint8_t len = strlen(msg); for (i=0;i < len ;i++){ //let pushByte worry about the intricacies of Enable, nibble order. pushByte(msg[i]); delayMicroseconds(40); // commands need > 37us to settle } }
void spi_cs(spi_bus_t* spi_bus, enum spi_cs_state state) { if (!spi_bus->cs_auto) { uint32_t v; v = spi_bus->regs->command1; if (state == SPI_CS_ASSERT) { setbits(v , SPI_CMD1_CS_SW_VAL); } else { clrbits(v , SPI_CMD1_CS_SW_VAL); } spi_bus->regs->command1 = v; } }
static int lm3559_torch(unsigned char brightness) { unsigned char value; if (brightness > 0x1F) brightness = 0x1F; lm3559_write(TORCH_BRIGHTNESS_REG_INDEX, brightness);//set torch brightness value = lm3559_read(ENABLE_REG_INDEX); clrbits(value, 0x01); setbits(value, 0x02); lm3559_write(ENABLE_REG_INDEX,value); return 0; }
/* * Copy buffer to clist. * Return number of bytes not transferred. */ int b_to_q(u_char *cp, int count, struct clist *clp) { int cc; u_char *p = cp; int s; if (count <= 0) return 0; s = spltty(); if (clp->c_cc == clp->c_cn) goto out; if (clp->c_cc == 0) { if (!clp->c_cs) { #if defined(DIAGNOSTIC) printf("b_to_q: required clalloc\n"); #endif clalloc(clp, 1024, 1); } clp->c_cf = clp->c_cl = clp->c_cs; } /* optimize this while loop */ while (count > 0 && clp->c_cc < clp->c_cn) { cc = clp->c_ce - clp->c_cl; if (clp->c_cf > clp->c_cl) cc = clp->c_cf - clp->c_cl; if (cc > count) cc = count; bcopy(p, clp->c_cl, cc); if (clp->c_cq) clrbits(clp->c_cq, clp->c_cl - clp->c_cs, cc); p += cc; count -= cc; clp->c_cc += cc; clp->c_cl += cc; if (clp->c_cl == clp->c_ce) clp->c_cl = clp->c_cs; } out: splx(s); return count; }
static void r8a66597_clock_disable(struct r8a66597 *r8a66597) { #if !defined(CONFIG_RZA_USB) r8a66597_bclr(r8a66597, SCKE, SYSCFG0); udelay(1); #if !defined(CONFIG_SUPERH_ON_CHIP_R8A66597) r8a66597_bclr(r8a66597, PLLC, SYSCFG0); r8a66597_bclr(r8a66597, XCKE, SYSCFG0); r8a66597_bclr(r8a66597, USBE, SYSCFG0); #endif #else r8a66597_bclr(r8a66597, SUSPM, SUSPMODE0); clrbits(le16, R8A66597_BASE0, UPLLE); mdelay(1); r8a66597_bclr(r8a66597, USBE, SYSCFG0); mdelay(1); #endif }
static int lm3559_flash(unsigned char timeout) { unsigned char value; if (timeout > 0x1f) return -1; // Set flash brightness lm3559_write(FLASH_BRIGHTNESS_REG_INDEX, (flash_brightness << 4) | flash_brightness); value = lm3559_read(FLASH_DURATION_REG_INDEX); clrbits(value, 0x1F); setbits(value, timeout); lm3559_write(FLASH_DURATION_REG_INDEX, value); value = lm3559_read(ENABLE_REG_INDEX); setbits(value, 0x03); lm3559_write(ENABLE_REG_INDEX, value); return 0; }
cap_t cap_from_text(const char *str) { cap_t res; __cap_s allones; int n; if (str == NULL) { _cap_debug("bad argument"); errno = EINVAL; return NULL; } if (!(res = cap_init())) return NULL; for (n = __CAP_BLKS; n--; ) allones._blk[n] = -1; _cap_debug("%s", str); for (;;) { char op; int flags = 0, listed=0; __cap_s list = {{0}}; /* skip leading spaces */ while (isspace((unsigned char)*str)) str++; if (!*str) { _cap_debugcap("e = ", &res->set.effective); _cap_debugcap("i = ", &res->set.inheritable); _cap_debugcap("p = ", &res->set.permitted); return res; } /* identify caps specified by this clause */ if (isalnum((unsigned char)*str) || *str == '_') { for (;;) { if (namcmp(str, "all")) { str += 3; list = allones; } else { n = lookupname(&str); if (n == -1) goto bad; list.raise_cap(n); } if (*str != ',') break; if (!isalnum((unsigned char)*++str) && *str != '_') goto bad; } listed = 1; } else if (*str == '+' || *str == '-') goto bad; /* require a list of capabilities */ else list = allones; /* identify first operation on list of capabilities */ op = *str++; if (op == '=' && (*str == '+' || *str == '-')) { if (!listed) goto bad; op = (*str++ == '+' ? 'P':'M'); /* skip '=' and take next op */ } else if (op != '+' && op != '-' && op != '=') goto bad; /* cycle through list of actions */ do { _cap_debug("next char = `%c'", *str); if (*str && !isspace(*str)) { switch (*str++) { /* Effective, Inheritable, Permitted */ case 'e': flags |= LIBCAP_EFF; break; case 'i': flags |= LIBCAP_INH; break; case 'p': flags |= LIBCAP_PER; break; default: goto bad; } } else if (op != '=') { _cap_debug("only '=' can be followed by space"); goto bad; } _cap_debug("how to read?"); switch (op) { /* how do we interpret the caps? */ case '=': case 'P': /* =+ */ case 'M': /* =- */ clrbits(&res->set.effective, &list); clrbits(&res->set.inheritable, &list); clrbits(&res->set.permitted, &list); /* fall through */ if (op == 'M') goto minus; case '+': if (flags & LIBCAP_EFF) setbits(&res->set.effective, &list); if (flags & LIBCAP_INH) setbits(&res->set.inheritable, &list); if (flags & LIBCAP_PER) setbits(&res->set.permitted, &list); break; case '-': minus: if (flags & LIBCAP_EFF) clrbits(&res->set.effective, &list); if (flags & LIBCAP_INH) clrbits(&res->set.inheritable, &list); if (flags & LIBCAP_PER) clrbits(&res->set.permitted, &list); break; } /* new directive? */ if (*str == '+' || *str == '-') { if (!listed) { _cap_debug("for + & - must list capabilities"); goto bad; } flags = 0; /* reset the flags */ op = *str++; if (!isalpha(*str)) goto bad; } } while (*str && !isspace(*str)); _cap_debug("next clause"); } bad: cap_free(&res); errno = EINVAL; return NULL; }
void disable() { // SHUT ALL OFF clrbits(LED_PORT, LED_PINS); }