Esempio n. 1
0
int main(int argc, char* argv[]) {
	const char* title = "\nam18x library for ecap!\n";
	int i;

	arm_intr_enable();
	systick_start();

	printk(title);
	printk("tary, compiled date : %s %s\n", __DATE__, __TIME__);

	psc_state_transition(PSC_GPIO, PSC_STATE_ENABLE);
	psc_state_transition(PSC_ECAP, PSC_STATE_ENABLE);

	gpio_set_mux(LCDC_BL_PWR, GPIO_DIR_OUTPUT);
	gpio_set_output1(LCDC_BL_PWR, GPIO_HIGH);

	#if 0
	gpio_set_mux(LCDC_BL_PWM, GPIO_DIR_OUTPUT);
	gpio_set_output1(LCDC_BL_PWM, GPIO_HIGH);
	#else
	syscfg_pinmux(LCDC_BL_PWM_PINMUX);
	#endif

	ecap_init(ECAP_HW);

	for (i = 0;; i += 5) {
		if (i > 100) {
			i = 0;
		}
		ecap_conf->duty = i;
		ecap_set_conf(ECAP_HW, ecap_conf);

		systick_sleep(1000);
	}

	return 0;
}
Esempio n. 2
0
void LCD_Init(void){
	
	GPIO->GPIO_PORT[OLED1_DISPLAY_MOSI_PIN/32].GPIO_GPERC = OELD1_DISPLAY_MOSI_GPIO;
	GPIO->GPIO_PORT[OLED1_DISPLAY_SCK_PIN/32].GPIO_GPERC = OLED1_DISPLAY_SCK_GPIO;
	
	gpio_set_mux(OELD1_DISPLAY_MOSI_GPIO, OLED1_DISPLAY_MOSI_PIN, MUX_PERIPHERAL_A);
	gpio_set_mux(OLED1_DISPLAY_SCK_GPIO, OLED1_DISPLAY_SCK_PIN, MUX_PERIPHERAL_B);
	
	// CS pin as output
	gpio_set_output(OLED1_DISPLAY_SS_GPIO, OLED1_DISPLAY_SS_PIN);
	GPIO->GPIO_PORT[OLED1_DISPLAY_SS_PIN/32].GPIO_OVRS = OLED1_DISPLAY_SS_GPIO;
	
	// OLED reset pin as output
	gpio_set_output(OLED1_DISPLAY_RESET_GPIO, OLED1_DISPLAY_RESET_PIN);
	GPIO->GPIO_PORT[OLED1_DISPLAY_RESET_PIN/32].GPIO_OVRS = OLED1_DISPLAY_RESET_GPIO;
	
	// OLED data/cmd pin as output
	gpio_set_output(OLED1_DATACMD_GPIO, OLED1_DATACMD_PIN);
	GPIO->GPIO_PORT[OLED1_DATACMD_PIN/32].GPIO_OVRS = OLED1_DATACMD_GPIO;

	// Enable SPI clock.
	PM->PM_UNLOCK = PM_UNLOCK_KEY(0xAA) | PM_UNLOCK_ADDR(0x028);
	PM->PM_PBAMASK |= PM_PBAMASK_SPI;
	
	// Set up SPI mode
	SPI->SPI_MR |= SPI_MR_MSTR | SPI_MR_MODFDIS | SPI_MR_PCS(0b1011);
	
	// Configure NPCS2
	SPI->SPI_CSR[2] |= SPI_CSR_SCBR(1) | SPI_CSR_DLYBCT(0x01) | SPI_CSR_CPOL;
	
	//Enable the SPI module.
	SPI->SPI_CR |= SPI_CR_SPIEN;
	
	LCD_Poweron_Reset();
	#if 1 //128x32
	//Set Display off
	LCD_buffer[0] = OLED_SET_DISPLAY_OFF;
	SPI_Send_Buffer(&LCD_buffer[0], 1, LCD_COMMAND);
	
	//Set Display clock Div Ration
	LCD_buffer[0] = OLED_SET_FREQUENCY;
	LCD_buffer[1] = 0x80;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);
	
	//Set Display mux ratio
	LCD_buffer[0] = OLED_SET_MUX_RATIO;
	LCD_buffer[1] = 0x1F;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);
	
	//Set Display offset
	LCD_buffer[0] = OLED_SET_DISP_OFFSET;
	LCD_buffer[1] = 0x00;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);
	
	//Set Display Start line
	LCD_buffer[0] = OLED_SET_START_LINE(0);
	SPI_Send_Buffer(&LCD_buffer[0], 1, LCD_COMMAND);

	//Enable charge pump
	LCD_buffer[0] = 0x8D;
	LCD_buffer[1] = 0x14;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);

	//Set Display Segment remap
	LCD_buffer[0] = OLED_SET_SEG_REMAP_REW;
	SPI_Send_Buffer(&LCD_buffer[0], 1, LCD_COMMAND);

	//Set Display COM Scan Direction
	LCD_buffer[0] = OLED_SET_COM_SCAN_DIR_REW;
	SPI_Send_Buffer(&LCD_buffer[0], 1, LCD_COMMAND);

	//Set COM pins HW Config
	LCD_buffer[0] = OLED_SET_COM_HW_CONF;
	LCD_buffer[1] = 0x02;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);

	//Set Contrast
	LCD_buffer[0] = OLED_SET_CONTRAST;
	LCD_buffer[1] = 0x8F;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);

	//Set Precharge
	LCD_buffer[0] = OLED_SET_PRECHARGE;
	LCD_buffer[1] = 0x22;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);

	//Set VCOMH Deselect Level
	LCD_buffer[0] = OLED_SET_VCOM_DESELECT;
	LCD_buffer[1] = 0x40;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);

	//Set Display On/Off
	LCD_buffer[0] = OLED_ENTIRE_DISPLAY_OFF;
	SPI_Send_Buffer(&LCD_buffer[0], 1, LCD_COMMAND);

	//Set Display Normal/Inverse
	LCD_buffer[0] = OLED_SET_DISPLAY_NORMAL;
	SPI_Send_Buffer(&LCD_buffer[0], 1, LCD_COMMAND);

	//Set Display On
	LCD_buffer[0] = OLED_SET_DISPLAY_ON;
	SPI_Send_Buffer(&LCD_buffer[0], 1, LCD_COMMAND);
	#else //128x64

	//Set Display off
	LCD_buffer[0] = OLED_SET_DISPLAY_OFF;
	SPI_Send_Buffer(&LCD_buffer[0], 1, LCD_COMMAND);
	
	//Set Display clock Div Ration
	LCD_buffer[0] = OLED_SET_FREQUENCY;
	LCD_buffer[1] = 0x80;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);
	
	//Set Display mux ratio
	LCD_buffer[0] = OLED_SET_MUX_RATIO;
	LCD_buffer[1] = 0x1F;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);
	
	//Set Display offset
	LCD_buffer[0] = OLED_SET_DISP_OFFSET;
	LCD_buffer[1] = 0x00;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);
	
	//Set Display Start line
	LCD_buffer[0] = OLED_SET_START_LINE(0);
	SPI_Send_Buffer(&LCD_buffer[0], 1, LCD_COMMAND);

	//Enable charge pump
	LCD_buffer[0] = 0x8D;
	LCD_buffer[1] = 0x14;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);

	//Set Display Segment remap
	LCD_buffer[0] = OLED_SET_SEG_REMAP_REW;
	SPI_Send_Buffer(&LCD_buffer[0], 1, LCD_COMMAND);

	//Set Display COM Scan Direction
	LCD_buffer[0] = OLED_SET_COM_SCAN_DIR_REW;
	SPI_Send_Buffer(&LCD_buffer[0], 1, LCD_COMMAND);

	//Set COM pins HW Config
	LCD_buffer[0] = OLED_SET_COM_HW_CONF;
	LCD_buffer[1] = 0x12;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);

	//Set Contrast
	LCD_buffer[0] = OLED_SET_CONTRAST;
	LCD_buffer[1] = 0x9F;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);

	//Set Precharge
	LCD_buffer[0] = OLED_SET_PRECHARGE;
	LCD_buffer[1] = 0x22;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);

	//Set VCOMH Deselect Level
	LCD_buffer[0] = OLED_SET_VCOM_DESELECT;
	LCD_buffer[1] = 0x30;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);

	//Set Display On/Off
	LCD_buffer[0] = OLED_ENTIRE_DISPLAY_OFF;
	SPI_Send_Buffer(&LCD_buffer[0], 1, LCD_COMMAND);

	//Set Display Normal/Inverse
	LCD_buffer[0] = OLED_SET_DISPLAY_NORMAL;
	SPI_Send_Buffer(&LCD_buffer[0], 1, LCD_COMMAND);

	//Set Display On
	LCD_buffer[0] = OLED_SET_DISPLAY_ON;
	SPI_Send_Buffer(&LCD_buffer[0], 1, LCD_COMMAND);
	#endif

	//Clear all RAM
	for(uint8_t page = 0; page<8; page++) {
		SPI_Send_Byte(LCD_COMMAND, OLED_SET_START_PAGE(page));
		for(uint8_t col = 0; col<128; col++){
			SPI_Send_Byte(LCD_DATA, 0x00);
		}
	}

	SPI_Send_Byte(LCD_COMMAND, OLED_SET_START_PAGE(0));

	LCD_buffer[0] = 0x22;
	LCD_buffer[1] = 0;
	LCD_buffer[2] = 3;
	SPI_Send_Buffer(&LCD_buffer[0], 3, LCD_COMMAND);

	LCD_buffer[0] = OLED_SET_ADDRESS_MODE;
	LCD_buffer[1] = 0x00;
	SPI_Send_Buffer(&LCD_buffer[0], 2, LCD_COMMAND);
}