void dash(void) { pinWrite(pin,1); delay_ms(DASH); pinWrite(pin,0); delay_ms(SPACE); }
void dit(void) { pinWrite(pin,1); delay_ms(DOT); pinWrite(pin,0); delay_ms(SPACE); }
/** Write an arbitrary glyph to the display */ void lcdWriteGlyph(int x, int y, const uint8_t *glyph, int width, int height, bool invert) { // Select the display spiConfig(false, true, true); pinWrite(g_sel, false); // Do the write writeGlyph(x, y, glyph, width, height, invert); // Deselect the display pinWrite(g_sel, true); }
/** Clear the display */ void lcdClear(bool invert) { // Select the display spiConfig(false, true, true); pinWrite(g_sel, false); // Set the position sendCommand(0x80); sendCommand(0x40); // Fill in the whole display for(int index = 0; index < (WIDTH * LINES); index++) sendData(invert?0xff:0x00); // Deselect the display pinWrite(g_sel, true); }
void shiftOut(unsigned char val) { char i; // Iterate over each bit, set data pin, and pulse the clock to send it // to the shift register for (i = 0; i < 8; i++) { pinWrite(DATA, (val & (1 << i))); pulseClock(); } }
/*----------------------------------------------------------------------------*/ static void blinkTask(void *argument) { static bool value = 0; const struct Pin * const pin = argument; pinWrite(*pin, value); value = !value; }
/*----------------------------------------------------------------------------*/ void pinOutput(struct Pin pin, bool value) { LPC_GPIO_Type * const reg = calcPort(pin.data); commonPinInit(pin); reg->DIR |= 1 << pin.data.offset; pinWrite(pin, value); }
/** Write a character to the display */ void lcdWriteCh(int x, int y, char ch, bool invert) { // Select the display spiConfig(false, true, true); pinWrite(g_sel, false); // Make sure the character is valid if((ch<0x20)||(ch>0x7f)) ch = 0x20; // Set the position sendCommand(0x80 | (x % WIDTH)); sendCommand(0x40 | (y % LINES)); // Write the character sendData(invert?0xff:0x00); writeGlyph(x + 1, y, BASE_FONT + (ch - 0x20) * (FONT_WIDTH - 2), FONT_WIDTH - 2, 1, invert); sendData(invert?0xff:0x00); // Deselect the display pinWrite(g_sel, true); }
/** Clear a region of the display */ void lcdClearRect(int y, int height, bool invert) { // Select the display spiConfig(false, true, true); pinWrite(g_sel, false); // Do the clear while(height) { // Set the position sendCommand(0x80); sendCommand(0x40 | (y % LINES)); // Fill the line for(int index=0; index<WIDTH; index++) sendData(invert?0xff:0x00); // Step to the next line height--; } // Deselect the display pinWrite(g_sel, true); }
// Reset to known state (as per what the DS3231 datasheet says) void i2c_resetState() { bit_clr(TWCR, TWEN); // Disable TWI pinMode(SDA, INPUT); pinPullup(SDA, PULLUP_ENABLE); delay(1); // Toggle SDL until SDA goes HIGH or times out byte count = 64; // 64 * 1ms = 64ms timeout while(!pinRead(SDA) && count--) { delay(1); pinWrite(SDL, TOGGLE); } // Back to normal pinMode(SDA, OUTPUT); pinMode(SDL, OUTPUT); pinWrite(SDA, HIGH); pinWrite(SDL, HIGH); }
void DrvDmLd4812::display() const { static byte r = 0; byte *p2 = _dm.output() + pgm_read_byte_near(LD4812_ROW_ADDRESS+r); for (byte i = 3, j = 0; i--;) { byte tmp = *p2++; for (byte c = 8; c--; j++) { pinWrite(_pin_col, tmp&0x80); pinWrite(_pin_row, j!=r); // row on when it is LOW this->shiftClock(); tmp <<= 1; } } this->shiftLatch(); if (r++ == LD4812_WIDTH) r = 0; }
/** Program entry point */ int main() { // First configure and latch our power pin. pinConfig(PIN_LATCH, DIGITAL_OUTPUT, 1); pinWrite(PIN_LATCH, true); // Call all the constructors for(void (**p)() = __init_array_start; p < __init_array_end; ++p) (*p)(); // Set up the rest of the power head pins pinConfig(PIN_INDICATOR, DIGITAL_OUTPUT, 0); pinWrite(PIN_INDICATOR, false); pinConfig(PIN_ACTION, DIGITAL_INPUT, WAKEUP); pinConfig(PIN_BATTERY, ANALOG); // Show we are on (2s indicator LED) // indicate(PATTERN_FULL, false); // TODO: Internal setup // Application setup setup(); // Main loop while(true) mainLoop(true); return 0; }
/** Initialise the LCD display * * @param dc the comand/data pin * @param reset the reset pin * @param sel device select pin */ void lcdInit(PIN dc, PIN reset, PIN sel) { // Save the pins pinConfig(dc, DIGITAL_OUTPUT, 0); g_dc = dc; pinConfig(reset, DIGITAL_OUTPUT, 0); g_reset = reset; pinConfig(sel, DIGITAL_OUTPUT, 1); g_sel = sel; // Reset the LCD pinWrite(g_reset, true); // Initialise the LCD spiConfig(false, true, true); pinWrite(g_sel, false); sendCommand(0x21); // LCD Extended Commands. sendCommand(0xB1); // Set LCD Vop (Contrast) 0xB1/0xA1. sendCommand(0x04); // Set Temp coefficent. //0x04 sendCommand(0x14); // LCD bias mode 1:48. //0x13 sendCommand(0x0C); // Normal display, horizontal addressing sendCommand(0x20); // LCD Normal commands sendCommand(0x0C); // Normal display, horizontal addressing // Deselect the display pinWrite(g_sel, true); }
/** Write a string to the display */ void lcdWriteStr(int x, int y, const char *str, bool invert) { // Select the display spiConfig(false, true, true); pinWrite(g_sel, false); while (*str) { // Make sure the character is valid char ch = *str; if((ch<0x20)||(ch>0x7f)) ch = 0x20; // Set the position sendCommand(0x80 | (x % WIDTH)); sendCommand(0x40 | (y % LINES)); // Write the character sendData(invert?0xff:0x00); writeGlyph(x + 1, y, BASE_FONT + (ch - 0x20) * (FONT_WIDTH - 2), FONT_WIDTH - 2, 1, invert); sendData(invert?0xff:0x00); // Move to the next character (and position) str++; x += FONT_WIDTH; } // Deselect the display pinWrite(g_sel, true); }
// Take the given 8-bit value and shift it out, LSB to MSB void shiftOut(unsigned char val) { //Set latch to low (should be already) P2OUT &= ~LATCH; char i; // Iterate over each bit, set data pin, and pulse the clock to send it // to the shift register for (i = 0; i < 8; i++) { pinWrite(DATA, (val & (1 << i))); pulseClock(); } // Pulse the latch pin to write the values into the storage register P2OUT |= LATCH; P2OUT &= ~LATCH; }
static inline void hubTask() { color_t pixel, pixel2; if (state == ST_PERIOD0) { //Period 0 - Shift row data pinReset(hub_time); //__HAL_TIM_SetAutoreload(&hubtim, period0 - 1); HUB_TIMER->ARR = period0 - 1; if (colorBit == HUB_COLOR_BIT0) { if (row == 0) { //Begin of Frame setBrightness(); if (hubBrightness == 0) { //Display turn off //__HAL_TIM_SetAutoreload(&hubtim, FRAME_PERIOD - 1); HUB_TIMER->ARR = FRAME_PERIOD - 1; pinSet(hub_time); return; } if (hubNeedRedraw) { swapPages(); setOrientSwap(); } bufLine = &DISPLAY[screen0]; bufLine2 = &bufLine[HUB_ROWS * screen_dy]; } outputRow(); } int red, green, blue; int red2, green2, blue2; buf = bufLine; buf2 = bufLine2; for (int x = 0; x < SCREEN_W; x++) { pixel = *buf; red = hubLUT[pixel.R]; green = hubLUT[pixel.G]; blue = hubLUT[pixel.B]; pixel2 = *buf2; red2 = hubLUT[pixel2.R]; green2 = hubLUT[pixel2.G]; blue2 = hubLUT[pixel2.B]; pinReset(hub_clk); pinWrite(hub_r1, red & colorBit); pinWrite(hub_g1, green & colorBit); pinWrite(hub_b1, blue & colorBit); pinWrite(hub_r2, red2 & colorBit); pinWrite(hub_g2, green2 & colorBit); pinWrite(hub_b2, blue2 & colorBit); buf += screen_dx; buf2 += screen_dx; pinSet(hub_clk); } period1n = period1N[colorI]; prescaler2n = prescaler2N[colorI]; colorBit >>= 1; colorI--; if (colorBit == 0) { colorBit = HUB_COLOR_BIT0; colorI = HUB_COLOR_I0; //Change Row row = (row + 1) & HUB_ROWS_MASK; bufLine += screen_dy; bufLine2 += screen_dy; } pinSet(hub_lat); state = ST_PERIOD1; pinReset(hub_lat); } else if (state == ST_PERIOD1) {
static inline void outputRow(void) { pinWrite(hub_a, row & 1); pinWrite(hub_b, row & 2); pinWrite(hub_c, row & 4); pinWrite(hub_d, row & 8); }
/** Send a command to the LCD */ static void sendCommand(uint8_t data) { pinWrite(g_dc, false); spiWrite(&data, 1); }
/** Send data to the LCD */ static void sendData(uint8_t data) { pinWrite(g_dc, true); spiWrite(&data, 1); }
/*----------------------------------------------------------------------------*/ void pinOutput(struct Pin pin, bool value) { commonPinInit(pin); ((LPC_GPIO_Type *)pin.reg)->DIR |= 1UL << pin.data.offset; pinWrite(pin, value); }
/*----------------------------------------------------------------------------*/ void pinToggle(struct Pin pin) { pinWrite(pin, !pinRead(pin)); }
/** Power down the device * * This function will completely power down the device. It is usually only * called in situations where continuing to operate would be dangerous or * possibly damage the sensor. */ void shutdown() { pinWrite(PIN_LATCH, false); // Enter endless loop while(true); }
void bit(int val) { pinWrite(pin,val); delay_us(DELAY); }