/** * @brief Initializes the PWM module * * This sets up the involved timers in a way that the PWM signal(s) are * generated. It needs to be called once before the module and its * functionality can be used. * * @note No signal(s) are actually being output until `pwm_on()` is invoked. * * @see PWM_RED * @see PWM_GREEN * @see PWM_BLUE */ void pwm_init() { PORT(PWM_RED) &= ~_BV(BIT(PWM_RED)); DDR(PWM_RED) |= _BV(BIT(PWM_RED)); #if (ENABLE_RGB_SUPPORT == 1) PORT(PWM_GREEN) &= ~_BV(BIT(PWM_GREEN)); DDR(PWM_GREEN) |= _BV(BIT(PWM_GREEN)); PORT(PWM_BLUE) &= ~_BV(BIT(PWM_BLUE)); DDR(PWM_BLUE) |= _BV(BIT(PWM_BLUE)); /* * Waveform generation mode: Fast PWM * Top: 0xFF * Update of OCRx: Bottom * Prescaler: 8 */ TCCR2A = _BV(WGM21) | _BV(WGM20); TCCR2B = _BV(CS21); #endif /* * Waveform generation mode: Fast PWM * Top: 0xFF * Update of OCRx: Bottom * Prescaler: 8 */ TCCR0A = _BV(WGM01) | _BV(WGM00); TCCR0B = _BV(CS01); }
//============================================================================= void KBD_init(void) { DDR(BEEPER) |= BEEPER_LINE; PORT(BEEPER) &= ~BEEPER_LINE; DDR(BUTTON_1) &= ~BUTTON_1_LINE; PORT(BUTTON_1) |= BUTTON_1_LINE; }
//---------------------------------------------------------------------------------------- // // Ustawienie wszystkich 4 linii danych jako WYj�cia // //---------------------------------------------------------------------------------------- static inline void data_dir_out(void) { DDR(LCD_D7PORT) |= (1<<LCD_D7); DDR(LCD_D6PORT) |= (1<<LCD_D6); DDR(LCD_D5PORT) |= (1<<LCD_D5); DDR(LCD_D4PORT) |= (1<<LCD_D4); }
/* Hardware initialization */ static void hwInit(void) { extFunc = eeprom_read_byte((uint8_t*)EEPROM_EXT_FUNC); #if 0 loadTempParams(); if (extFunc == USE_DS18B20) { ds18x20SearchDevices(); tempInit(); /* Init temperature control */ } #endif I2CInit(); /* I2C bus */ displayInit(); /* Load params and text labels before fb scan started */ rcInit(); /* IR Remote control */ inputInit(); /* Buttons/encoder polling */ adcInit(); /* Analog-to-digital converter */ sei(); /* Gloabl interrupt enable */ //tunerInit(extFunc); /* Tuner */ DDR(STMU_STBY) |= STMU_STBY_LINE; /* Standby port */ DDR(STMU_MUTE) |= STMU_MUTE_LINE; /* Mute port */ sndInit(extFunc); /* Load labels/icons/etc */ setStbyTimer(0); return; }
/* initializes lcd for use, this or lcd_init_wo_ir MUST be called first * * Note: this function does NOT assume internel reset circuit power * conditions were met */ void lcd_init(void) { int i; /* set control pins as output */ DDR(EN_PORT) |= _BV(EN_PIN); DDR(RW_PORT) |= _BV(RW_PIN); DDR(RS_PORT) |= _BV(RS_PIN); /* set data pins as output */ data_pins_out(); /* wait until lcd is finished booting */ _delay_us(BOOT_DELAY); /* set control pins for function set */ for (i = 0; i < 3; i++) { set_rs_low(); set_rw_low(); set_data_pins(F_SET_INITIAL); toggle_e(); _delay_us(INIT_DELAY); } /* final function set, set's 8bit operation, 2-line disp, 5x8 font */ set_data_pins(F_SET_DEFAULT); toggle_e(); _delay_us(INIT_DELAY); lcd_command(DISP_OFF); /* display off */ lcd_command(CLEAR_DISP); /* display clear*/ lcd_command(ENTRY_DEFAULT); /* set entry mode to INC, no shift */ lcd_command(DISP_ON); /* display on */ }
//---------------------------------------------------------------------------------------- // // Ustawienie wszystkich 4 linii danych jako WEj�cia // //---------------------------------------------------------------------------------------- static inline void data_dir_in(void) { DDR(LCD_D7PORT) &= ~(1<<LCD_D7); DDR(LCD_D6PORT) &= ~(1<<LCD_D6); DDR(LCD_D5PORT) &= ~(1<<LCD_D5); DDR(LCD_D4PORT) &= ~(1<<LCD_D4); }
/* * Initialize SPI bus. */ void spi_init(void) { static unsigned char spi_inited = 0; if (spi_inited) return; /* Initalize ports for communication with SPI units. */ /* CSN=SS and must be output when master! */ #if defined (__AVR_ATmega644P__) /*SPI Specific Initialization.*/ /* Set SS, CLK and MOSI as output. */ /* * The DDxn bit in the DDRx Register selects the direction of this pin. If DDxn is written logic one, * Pxn is configured as an output pin. If DDxn is written logic zero, Pxn is configured as an input * pin. */ printf("\n spi_init starting \n"); // 1 = Output, 0 = Input //CE(Chip Enable Rx or Tx), Output--PD6 //CSN(SPI Chip Select), Output--PD4 //SCK(SPI Clock), Output--PB7/SCL //MISO(SPI Data Input), Input--PB6/MISO //MOSI(SPI Data Output), Output--PB5/MOSI //IRQ, Output--None DDR(SSPORT) |= BV(SSPIN) | BV(CEPIN); //DDR(SSPORT) |= BV(CEPIN); //chip enable, need remove this chip enable pin in the HW DDR(SPIPORT) |= BV(SCKPIN) | BV(MOSIPIN); /* If PORTxn is written logic one when the pin is configured as an output pin, the port pin is driven * high (one). If PORTxn is written logic zero when the pin is configured as an output pin, the port * pin is driven low (zero). */ //PORT(SPIPORT) |= BV(SCKPIN) | BV(MOSIPIN); //driven to high PORT(SSPORT) |= BV(SSPIN) | BV(CEPIN); //driven to high //Enable pull-up resistors (page 74), if it is input, set PORTx means pull-up PORT(SSPORT) |= BV(MISOPIN); //Pulling up a pin that is grounded will cause 90uA current leak printf("\n PORTB=0x%x, DDRB=0x%x, PORTD:0x%x, DDRD=0x%x \n", PORT(SPIPORT), DDR(SPIPORT), PORT(SSPORT), DDR(SSPORT) ); #else #error "\n No CPU select, spi_init() failed in spi.c \n" #endif #if USE_SPI_SIMULATOR #else /* In the SPI master mode, must set SS(SlaveSelect) to output, actually this pin should connect to the CS pin the SPI slave device */ DDR(SPIPORT) |= BV(4); PORT(SPIPORT) |= BV(4); /* Enable SPI module and master operation. */ SPCR = BV(SPE) | BV(MSTR) |BV(SPR0); // | BV(SPIE); /* Enable doubled SPI speed in master mode. */ //SPSR = BV(SPI2X); printf("\n spi end, SPCR=0x%x\n", SPCR); #endif }
void config_right_motor() { DDR(RIGHT_MOTOR_A_PORT) |= RIGHT_MOTOR_A; DDR(RIGHT_MOTOR_B_PORT) |= RIGHT_MOTOR_B; shift_right_motor_brake(); TCCR2A = 0x03; //WGM(2:0) = "011" : Fast-PWM, TOP = 0xFF, BOTTOM = 0x00 TCCR2B = 0x01; //CS(2:0) = "001" : select I/Oclk OCR2A = 0x00; OCR2B = 0x00; }
void config_left_motor() { DDR(LEFT_MOTOR_A_PORT) |= LEFT_MOTOR_A; DDR(LEFT_MOTOR_B_PORT) |= LEFT_MOTOR_B; shift_left_motor_brake(); TCCR0A = 0x03; TCCR0B = 0x01; OCR0A = 0x00; OCR0B = 0x00; }
void eeprom_init(void) { // piny dla !CS jako wyjœcia DDR(EEPROM_SS_PORT) |= (1<<EEPROM_SS_PIN); // bank #0 DDR(EEPROM_SS_PORT) |= (1<<(EEPROM_SS_PIN+1)); // bank #1 // ustaw na CS stan wysoki spi_unselect(EEPROM_SS_PORT, EEPROM_SS_PIN); spi_unselect(EEPROM_SS_PORT, EEPROM_SS_PIN + 1); }
void lcdDriver_init() { DDR(DISPLAY_CS_PORT) |= (1 << DISPLAY_CS_PIN); DDR(DISPLAY_WR_PORT) |= (1 << DISPLAY_WR_PIN); DDR(DISPLAY_RD_PORT) |= (1 << DISPLAY_RD_PIN); DDR(DISPLAY_A0_PORT) |= (1 << DISPLAY_A0_PIN); DISPLAY_WR_PORT |= (1 << DISPLAY_WR_PIN); DISPLAY_RD_PORT |= (1 << DISPLAY_RD_PIN); DISPLAY_A0_PORT &= ~(1 << DISPLAY_A0_PIN); }
static void I2CswSendBit(uint8_t bit) { if (bit) DDR(I2C_SDA) &= ~I2C_SDA_LINE; // Pullup SDA = 1 else DDR(I2C_SDA) |= I2C_SDA_LINE; // Active SDA = 0 I2CswGetBit(); return; }
void I2CswStop(void) { DDR(I2C_SCL) |= I2C_SCL_LINE; // Active SCL = 0 DDR(I2C_SDA) |= I2C_SDA_LINE; // Active SDA = 0 _delay_us(5); DDR(I2C_SCL) &= ~I2C_SCL_LINE; // Pullup SCL = 1 _delay_us(5); DDR(I2C_SDA) &= ~I2C_SDA_LINE; // Pullup SDA = 1 return; }
//============================================================================= void KBD_init(void) { DDR(BEEPER) |= BEEPER_LINE; PORT(BEEPER) |= BEEPER_LINE; DDR(BUTTON_LEFT) &= ~(1 << BUTTON_LEFT_LINE); PORT(BUTTON_LEFT) |= (1 << BUTTON_LEFT_LINE); DDR(BUTTON_SET) &= ~(1 << BUTTON_SET_LINE); PORT(BUTTON_SET) |= (1 << BUTTON_SET_LINE); DDR(BUTTON_RIGHT) &= ~(1 << BUTTON_RIGHT_LINE); PORT(BUTTON_RIGHT) |= (1 << BUTTON_RIGHT_LINE); }
void open_log_init(void) { uart1Init(); uartSetBaudRate(1,9600); OPEN_LOG_PWR_PORT &= ~(1<<OPEN_LOG_PWR_PIN); DDR(OPEN_LOG_PWR_PORT) |= (1<<OPEN_LOG_PWR_PIN); // setup our reset port and pin, hold reset high OPEN_LOG_RESET_PORT |= (1<<OPEN_LOG_RESET_PIN); DDR(OPEN_LOG_RESET_PORT) |= (1<<OPEN_LOG_RESET_PIN); }
static uint8_t I2CswGetBit(void) { uint8_t ret; _delay_us(5); DDR(I2C_SCL) &= ~I2C_SCL_LINE; // Pullup SCL = 1 _delay_us(5); ret = PIN(I2C_SDA) & I2C_SDA_LINE; DDR(I2C_SCL) |= I2C_SCL_LINE; // Active SCL = 0 return ret; }
void I2CswStart(uint8_t addr) { DDR(I2C_SCL) &= ~I2C_SCL_LINE; // Pullup SCL = 1 DDR(I2C_SDA) &= ~I2C_SDA_LINE; // Pullup SDA = 1 _delay_us(5); DDR(I2C_SDA) |= I2C_SDA_LINE; // Active SDA = 0 _delay_us(5); DDR(I2C_SCL) |= I2C_SCL_LINE; // Active SCL = 0 I2CswWriteByte(addr); return; }
void borg_hw_init() { DDR(COLPORT1) = 0xff; DDR(COLPORT2) = 0xff; SET_DDR(LATCH_R); SET_DDR(LATCH_G); SET_DDR(LATCH_B); timer1_on(); // activate watchdog timer wdt_reset(); wdt_enable(0x00); // 17ms watchdog }
void pcm2705Init() { DDR(PCM2705_MD) |= PCM2705_MD_LINE; DDR(PCM2705_MC) |= PCM2705_MC_LINE; DDR(PCM2705_MS) |= PCM2705_MS_LINE; PORT(PCM2705_MD) |= PCM2705_MD_LINE; PORT(PCM2705_MC) &= ~PCM2705_MC_LINE; PORT(PCM2705_MS) |= PCM2705_MS_LINE; DDR(PCM2705_DPLUS) |= PCM2705_DPLUS_LINE; PORT(PCM2705_DPLUS) |= PCM2705_DPLUS_LINE; }
static void ds18x20SendBit(uint8_t bit) { DDR(ONE_WIRE) |= ONE_WIRE_LINE; /* Pin as output (0) */ PORT(ONE_WIRE) &= ~ONE_WIRE_LINE; /* Set active 0 */ _delay_us(5); if (!bit) _delay_us(50); DDR(ONE_WIRE) &= ~ONE_WIRE_LINE; /* Pin as input (1) */ PORT(ONE_WIRE) |= ONE_WIRE_LINE; /* Enable pull-up resitor */ _delay_us(5); if (bit) _delay_us(50); return; }
static void ds18x20SendBit(uint8_t bit) { DDR(ONE_WIRE) |= ONE_WIRE_LINE; // Pin as output (0) PORT(ONE_WIRE) &= ~ONE_WIRE_LINE; // Set active 0 _delay_us(6); if (!bit) _delay_us(54); DDR(ONE_WIRE) &= ~ONE_WIRE_LINE; // Pin as input (1) PORT(ONE_WIRE) |= ONE_WIRE_LINE; // Enable pull-up resitor _delay_us(10); if (bit) _delay_us(54); return; }
void UART0_init(void) // inicjalizacja UART0 { #ifdef UART0_DE_PORT sbi(DDR(UART0_DE_PORT),UART0_DE_BIT); // ustaw kierunek linii DE konwertera RS485 #endif _UBRR_ = (u08)UART_CONST; // ustaw prêdkoœæ transmisji #ifdef _UBRR0H_ _UBRR0H_ = UART0_CONST >> 8; // ustaw prêdkoœæ transmisji #endif #ifdef UART0_BUF_SIZE // je¿eli UART0 ma pracowaæ na przerwaniach #ifdef UART0_DE_PORT _UCR_ = _BV(RXEN0)|_BV(TXEN0)|_BV(RXCIE0)|_BV(TXCIE0); #else _UCR_ = _BV(RXEN0)|_BV(TXEN0)|_BV(RXCIE0); #endif // w³¹cz odbiór, nadawanie i przerwania sei(); // w³¹cz przerwania #else // jeœli UART0 pracuje bez u¿ycia przerwañ _UCR_ = _BV(RXEN0)|_BV(TXEN0); // w³¹cz odbiór i nadawanie #endif //UART0_BUF_SIZE }
void sd_host_init(void) { spi_master_init(); /* SD CS = output */ DDR(SD_CS_PORT) |= (1 << SD_CS_IX); sd_cs_release(); }
uint8_t s6b0108_inbyte(uint8_t rs) { uint8_t x; if(rs) s6b0108_wait_ready(); DDR(S6B0108_PDATA)=INPUT; PORT(S6B0108_PDATA)=0x00; _delay_us(0.3); if (rs) { // reading data PORT(S6B0108_PCMD) |= (_BV(RW) | _BV(RS)); _delay_us(0.2); //first access is to copy display data to display output register PORT(S6B0108_PCMD) |= _BV(E); _delay_us(2.0); PORT(S6B0108_PCMD) &= ~_BV(E); _delay_us(3.0); // 0.5 should be enough but doesn't work } else { // reading status PORT(S6B0108_PCMD) |= _BV(RW); PORT(S6B0108_PCMD) &= ~_BV(RS); _delay_us(0.2); } PORT(S6B0108_PCMD) |= _BV(E); _delay_us(2.0); // 0.32 should be enough but doesn't work x = PIN(S6B0108_PDATA); _delay_us(0.2); PORT(S6B0108_PCMD) &= ~_BV(E); PORT(S6B0108_PCMD) &= ~( _BV(RS) | _BV(RW) | _BV(E) ); return x; }
void system_run(void) { // Inicjacja wyprowadzeñ DDR(LCD_CTRLPORT) = (1<<LCD_E | 1<<LCD_RW | 1<<LCD_RS | 1<<LCD_LED); PORT(LCD_CTRLPORT) = ~(1<<LCD_E | 1<<LCD_LED); PORT(SW_PORT) = 1<<SW1 | 1<<SW2; // Inicjacja wyœwietlacza lcd_Init(); lcd_SetStatus(LCD_STATUS_DISP); // Inicjacja timera systemowego TCCR2 = 1<<WGM21 /*CTC*/ | 1<<CS22 | 1<<CS21 | 1<<CS20 /*clk:1024*/; OCR2 = 78; // oko³o 10ms // Przerwania TIMSK = 1<<OCIE2 /*porównania z timera 2*/; sei(); // Wyœwietlenie zapytania o jêzyk fputs_P(PSTR("S1 - "), lcd_GetFile()); fputs_P(langsys_GetLangName(0), lcd_GetFile()); lcd_GoTo(0, 1); fputs_P(PSTR("S2 - "), lcd_GetFile()); fputs_P(langsys_GetLangName(1), lcd_GetFile()); lcd_Update(); // Oczekiwanie na przycisk // Wywo³anie aplikacji app_run(); }
void keys_init() { // konfiguracja pinów jako wejœcia z podci¹ganiem DDR(KEYS_S1_PORT) &= ~(1<<KEYS_S1_BIT); DDR(KEYS_S2_PORT) &= ~(1<<KEYS_S2_BIT); DDR(KEYS_S3_PORT) &= ~(1<<KEYS_S3_BIT); DDR(KEYS_S4_PORT) &= ~(1<<KEYS_S4_BIT); KEYS_S1_PORT |= (1<<KEYS_S1_BIT); KEYS_S2_PORT |= (1<<KEYS_S2_BIT); KEYS_S3_PORT |= (1<<KEYS_S3_BIT); KEYS_S4_PORT |= (1<<KEYS_S4_BIT); // stan klawiszy keys_state = 0x0f; keys_pressed_mask = 0x00; }
static int mb86s70_gpio_direction_input(struct gpio_chip *gc, unsigned gpio) { struct mb86s70_gpio_chip *gchip = gpiochip_get_data(gc); unsigned long flags; unsigned char val; spin_lock_irqsave(&gchip->lock, flags); val = readl(gchip->base + DDR(gpio)); val &= ~OFFSET(gpio); writel(val, gchip->base + DDR(gpio)); spin_unlock_irqrestore(&gchip->lock, flags); return 0; }
void InitialzeLCD(void){ sbi(DDR(LCD_BACKLIGHT_PORT),LCD_BACKLIGHT_PIN); //setting the LCD backlight pin and port sbi(LCD_BACKLIGHT_PORT,LCD_BACKLIGHT_PIN); glcd_init(); // initializes the LCD glcd_set_contrast(50); // sets constrast to default value glcd_clear(); // clears screen and buffer }
//---------------------------------------------------------------------------------------- // // ******* INICJALIZACJA WY�WIETLACZA LCD ******** // //---------------------------------------------------------------------------------------- void lcd_init(void) { // inicjowanie pin�w port�w ustalonych do pod��czenia z wy�wietlaczem LCD // ustawienie wszystkich jako wyj�cia data_dir_out(); DDR(LCD_RSPORT) |= (1<<LCD_RS); DDR(LCD_EPORT) |= (1<<LCD_E); DDR(LCD_BACKGROUNDPORT) |= (1<<LCD_BL); #if USE_RW == 1 DDR(LCD_RWPORT) |= (1<<LCD_RW); #endif // wyzerowanie wszystkich linii steruj�cych PORT(LCD_RSPORT) &= ~(1<<LCD_RS); PORT(LCD_EPORT) &= ~(1<<LCD_E); #if USE_RW == 1 PORT(LCD_RWPORT) &= ~(1<<LCD_RW); #endif _delay_ms(15); PORT(LCD_RSPORT) &= ~(1<<LCD_RS); PORT(LCD_RWPORT) &= ~(1<<LCD_RW); // jeszcze nie mo�na u�ywa� Busy Flag lcd_sendHalf(LCDC_FUNC|LCDC_FUNC8B); _delay_ms(4.1); lcd_sendHalf(LCDC_FUNC|LCDC_FUNC8B); _delay_us(100); lcd_sendHalf(LCDC_FUNC|LCDC_FUNC4B); _delay_us(100); // ju� mo�na u�ywa� Busy Flag // tryb 4-bitowy, 2 wiersze, znak 5x7 lcd_write_cmd( LCDC_FUNC|LCDC_FUNC4B|LCDC_FUNC2L|LCDC_FUNC5x7 ); // wy��czenie kursora lcd_write_cmd( LCDC_ONOFF|LCDC_CURSOROFF ); // w��czenie wy�wietlacza lcd_write_cmd( LCDC_ONOFF|LCDC_DISPLAYON ); // przesuwanie kursora w prawo bez przesuwania zawarto�ci ekranu lcd_write_cmd( LCDC_ENTRY|LCDC_ENTRYR ); // kasowanie ekranu lcd_cls(); lcd_backgroundLedOn(); }
static uint8_t ds18x20IsOnBus(void) { uint8_t ret; DDR(ONE_WIRE) |= ONE_WIRE_LINE; // Pin as output (0) PORT(ONE_WIRE) &= ~ONE_WIRE_LINE; // Set active 0 _delay_us(480); // Reset DDR(ONE_WIRE) &= ~ONE_WIRE_LINE; // Pin as input (1) PORT(ONE_WIRE) |= ONE_WIRE_LINE; // Enable pull-up resitor _delay_us(70); // Wait for response ret = !(PIN(ONE_WIRE) & ONE_WIRE_LINE); _delay_us(410); return ret; }