Пример #1
0
/*==============================================================================
  hal_ctrlPinInit()
 =============================================================================*/
void * 	hal_ctrlPinInit(en_targetExtPin_t e_pinType)
{
	struct port_config pin_conf;
	port_get_config_defaults(&pin_conf);
	pinDesc_t * p_pin = NULL;
	
	/* Configure SPI interface */
	port_get_config_defaults(&pin_conf);

	switch (e_pinType){
		case E_TARGET_RADIO_RST:
			pin_conf.direction  = PORT_PIN_DIR_OUTPUT;
			port_pin_set_config(st_rst, &pin_conf);	//	RST_PIN
			port_pin_set_output_level(st_rst, true);	//	RST_PIN
			p_pin = &st_rst;
			break;
		case E_TARGET_RADIO_SLPTR:
			pin_conf.direction  = PORT_PIN_DIR_OUTPUT;
			port_pin_set_config(st_slp_tr, &pin_conf);	//	SLP_PIN
			port_pin_set_output_level(st_slp_tr, true);	//	SLP_PIN
			p_pin = &st_slp_tr;
			break;
		default:
			free(p_pin);
			break;
	}

	return p_pin;
} /* hal_ctrlPinInit */
Пример #2
0
/**
 * \internal
 * \brief Test for external interrupt detection by polling.
 *
 * This test changes the logic level of PB05 from high to low
 * so that the external interrupt channel detects the edge.
 *
 * Detection is tested for both rising and falling edges.
 *
 * \param test Current test case.
 */
static void run_extint_polled_mode_test(const struct test_case *test)
{
	/* Testing the falling edge detection */
	/* Generate falling edge */
	port_pin_set_output_level(GPIO_TEST_PIN_EXTINT, false);
	/* Wait for the pin level to stabilize */
	delay_ms(1);
	result = extint_chan_is_detected(EIC_TEST_CHANNEL);
	test_assert_true(test, result,
			"External interrupt falling edge detection by polling failed");
	extint_chan_clear_detected(EIC_TEST_CHANNEL);

	/* Testing the rising edge detection */
	result = false;
	eic_conf.detection_criteria = EXTINT_DETECT_RISING;
	extint_chan_set_config(EIC_TEST_CHANNEL, &eic_conf);
	/* Generate rising edge */
	port_pin_set_output_level(GPIO_TEST_PIN_EXTINT, true);
	/* Wait for the pin level to stabilize */
	delay_ms(1);
	result = extint_chan_is_detected(EIC_TEST_CHANNEL);
	test_assert_true(test, result,
			"External interrupt rising edge detection by polling failed");
	extint_chan_clear_detected(EIC_TEST_CHANNEL);
}
Пример #3
0
void SPI_Read_AD5421(uint8_t* data)
{
	port_pin_set_output_level(PIN_PA18, 0);
	//spi_read_buffer_wait(&spi_master_instance_AD5421, data, 3, 0);
	spi_transceive_buffer_wait(&spi_master_instance_AD5421, data, data, 3);
	port_pin_set_output_level(PIN_PA18, 1);	
}
Пример #4
0
void SPI_Read_ADXL(uint8_t* data)
{	
	port_pin_set_output_level(PIN_PA06, 0);
	//spi_read_buffer_wait(&spi_master_instance_ADXL, data, 2, 0);
	spi_transceive_buffer_wait(&spi_master_instance_ADXL, data, data, 2);
	port_pin_set_output_level(PIN_PA06, 1);
}
/**
 * \internal
 * \brief Perform hardware reset of the PHY.
 */
static inline void ksz8851snl_hard_reset(void)
{
	/* Perform hardware reset with respect to the reset timing from the datasheet. */
	port_pin_set_output_level(KSZ8851SNL_RSTN_PIN, false);
	delay_ms(100);
	port_pin_set_output_level(KSZ8851SNL_RSTN_PIN, true);
	delay_ms(100);
}
Пример #6
0
/**
 * \brief Set LED0 on Xplained board on/off
 */
void led_set(bool state)
{
	if (state) {
		port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);
	} else {
		port_pin_set_output_level(LED_0_PIN, LED_0_INACTIVE);
	}	
}
Пример #7
0
/* Updates the board LED to the current button state. */
static void update_led_state(void)
{
	bool pin_state = port_pin_get_input_level(BUTTON_0_PIN);
	if (pin_state) {
		port_pin_set_output_level(LED_0_PIN, LED_0_INACTIVE);
	} else {
		port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);
	}
}
Пример #8
0
/**
 *	@fn		nm_bsp_reset
 *	@brief	Reset NMC1500 SoC by setting CHIP_EN and RESET_N signals low,
 *           CHIP_EN high then RESET_N high
 */
void nm_bsp_reset(void)
{
	port_pin_set_output_level(CONF_WINC_PIN_CHIP_ENABLE, false);
	port_pin_set_output_level(CONF_WINC_PIN_RESET, false);
	nm_bsp_sleep(100);
	port_pin_set_output_level(CONF_WINC_PIN_CHIP_ENABLE, true);
	nm_bsp_sleep(100);
	port_pin_set_output_level(CONF_WINC_PIN_RESET, true);
	nm_bsp_sleep(100);
}
Пример #9
0
void
leds_arch_set(unsigned char new_led_status)
{
  led_status = new_led_status;
  if (led_status & LEDS_GREEN) {
    port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);
  } else {
    port_pin_set_output_level(LED_0_PIN, LED_0_INACTIVE);
  }
}
Пример #10
0
//------------  --------------------
//-----湿度读取子程序 ------------
//----------------------  ----------
//----以下变量均为全局变量--------
//----温度高8位== U8T_data_H------
//----温度低8位== U8T_data_L------
//----湿度高8位== U8RH_data_H-----
//----湿度低8位== U8RH_data_L-----
//----校验 8位 == U8checkdata-----
//----调用相关子程序如下----------
//---- delay_us();, delay_ms();COM();
//---------------------    -----------
void RH(void)
{
	//主机拉低18ms
	port_pin_set_config(DATA, &pinc);
	port_pin_set_output_level(DATA, false);
	delay_ms(18);
	port_pin_set_output_level(DATA, true);
	//总线由上拉电阻拉高 主机延时20us
	delay_us(20);
	//主机设为输入 判断从机响应信号
	port_pin_set_output_level(DATA, true);
	port_pin_set_config(DATA, &pini);
	//判断从机是否有低电平响应信号 如不响应则跳出,响应则向下运行
	
	if(!port_pin_get_input_level(DATA)) //T !
	{
		U8FLAG=2;
		//判断从机是否发出 80us 的低电平响应信号是否结束
		
		while((!port_pin_get_input_level(DATA))&&U8FLAG++);
		U8FLAG=2;
		
		//判断从机是否发出 80us 的高电平,如发出则进入数据接收状态
		while((port_pin_get_input_level(DATA))&&U8FLAG++);
		//数据接收状态
		Run_COM();
		
		U8RH_data_H_temp=U8comdata;
		Run_COM();
		U8RH_data_L_temp=U8comdata;
		Run_COM();
		U8T_data_H_temp=U8comdata;
		Run_COM();
		U8T_data_L_temp=U8comdata;
		Run_COM();
		U8checkdata_temp=U8comdata;
		port_pin_set_config(DATA, &pinc);
		port_pin_set_output_level(DATA, true);
		//数据校验
		
		U8Temp=(U8T_data_H_temp+U8T_data_L_temp+U8RH_data_H_temp+U8RH_data_L_temp);
		
		if(U8Temp==U8checkdata_temp)
		{
			
			U8RH_data_H=U8RH_data_H_temp;
			U8RH_data_L=U8RH_data_L_temp;
			U8T_data_H=U8T_data_H_temp;
			U8T_data_L=U8T_data_L_temp;
			U8checkdata=U8checkdata_temp;
			
		}//fi
	}//fi
}
Пример #11
0
/**
 * \brief      Init the radio
 * \return     Returns success/fail
 * \retval 0   Success
 */
static int
rf212_init(void)
{
  volatile uint8_t regtemp;
   uint8_t radio_state;  /* don't optimize this away, it's important */
  //uint8_t temp;
  PRINTF("RF212: init.\n");

  /* init SPI and GPIOs, wake up from sleep/power up. */
  //rf212_arch_init();
  trx_spi_init();
 
  /* reset will put us into TRX_OFF state */
  /* reset the radio core */
  port_pin_set_output_level(AT86RFX_RST_PIN, false);
  delay_cycles_ms(1);
  port_pin_set_output_level(AT86RFX_RST_PIN, true);
  
  port_pin_set_output_level(AT86RFX_SLP_PIN, false); /*wakeup from sleep*/

  /* before enabling interrupts, make sure we have cleared IRQ status */
  regtemp = trx_reg_read(RF212_REG_IRQ_STATUS);
  printf("After wake from sleep\n");
  radio_state = rf212_status();
  printf("After arch read reg: state 0x%04x\n", radio_state);
 
  /* Assign regtemp to regtemp to avoid compiler warnings */
  regtemp = regtemp;
if(radio_state == STATE_P_ON) {
	trx_reg_write(RF212_REG_TRX_STATE, TRXCMD_TRX_OFF);
	}  
  trx_irq_init((FUNC_PTR)rf212_interrupt_poll);
  ENABLE_TRX_IRQ();  
  system_interrupt_enable_global();
  /* Configure the radio using the default values except these. */
  trx_reg_write(RF212_REG_TRX_CTRL_1,      RF212_REG_TRX_CTRL_1_CONF);
  trx_reg_write(RF212_REG_PHY_CC_CCA,      RF212_REG_PHY_CC_CCA_CONF);
  trx_reg_write(RF212_REG_PHY_TX_PWR_CONF, RF212_REG_PHY_TX_PWR_CONF);
  //temp = rf212_arch_read_reg(RF212_REG_TRX_CTRL_2);
  trx_reg_write(RF212_REG_TRX_CTRL_2, RF212_REG_TRX_CTRL_2_CONF);
  trx_reg_write(RF212_REG_IRQ_MASK,        RF212_REG_IRQ_MASK_CONF);
#if HW_CSMA_FRAME_RETRIES
  trx_bit_write(SR_MAX_FRAME_RETRIES, 3);
  trx_bit_write(SR_MAX_CSMA_RETRIES, 4);
#else  
  trx_bit_write(SR_MAX_FRAME_RETRIES, 0);
  trx_bit_write(SR_MAX_CSMA_RETRIES, 7);
#endif  
  SetPanId(IEEE802154_CONF_PANID);
  rf_generate_random_seed();
  /* start the radio process */
  process_start(&rf212_radio_process, NULL);
  return 0;
}
Пример #12
0
/*---------------------------------------------------------------------------*/
static int
write_buffer(const unsigned char * buffer, uint8_t len)
{
  port_pin_set_output_level(RS485_TXE, true);
  if (usart_write_buffer_wait(&usart_instance, buffer, len) == STATUS_OK) {
    port_pin_set_output_level(RS485_TXE, false);
    return len;
  } else {
    return -1;
  }
}
Пример #13
0
/*---------------------------------------------------------------------------*/
static int
write_byte(const unsigned char b)
{
  port_pin_set_output_level(RS485_TXE, true);
  if (usart_write_wait(&usart_instance, b) == STATUS_OK) {
    port_pin_set_output_level(RS485_TXE, false);
    return 1;
  } else {
    return -1;
  }
}
Пример #14
0
/**
 *	@fn		nm_bsp_deinit
 *	@brief	De-iInitialize BSP
 *	@return	0 in case of success and -1 in case of failure
 */
sint8 nm_bsp_deinit(void)
{
	struct port_config pin_conf;
	port_get_config_defaults(&pin_conf);
	/* Configure control pins as input no pull up. */
	pin_conf.direction  = PORT_PIN_DIR_INPUT;
	pin_conf.input_pull = PORT_PIN_PULL_NONE;
	port_pin_set_output_level(CONF_WINC_PIN_CHIP_ENABLE, false);
	port_pin_set_output_level(CONF_WINC_PIN_RESET, false);
	port_pin_set_config(CONF_WINC_SPI_INT_PIN, &pin_conf);
	return M2M_SUCCESS;
}
Пример #15
0
void _hal_ledInit( void )
{
    struct port_config pin_conf;
    port_get_config_defaults(&pin_conf);

    /* Configure LEDs as outputs, turn them off */
    pin_conf.direction = PORT_PIN_DIR_OUTPUT;
    port_pin_set_config(LED_0_PIN, &pin_conf);
    port_pin_set_output_level(LED_0_PIN, LED_0_INACTIVE);
    port_pin_set_config(LED_1_PIN, &pin_conf);
    port_pin_set_output_level(LED_1_PIN, LED_1_INACTIVE);
    port_pin_set_config(LED_2_PIN, &pin_conf);
    port_pin_set_output_level(LED_2_PIN, LED_2_INACTIVE);
}
Пример #16
0
/*
 *	@fn		init_chip_pins
 *	@brief	Initialize reset, chip enable and wake pin
 */
static void init_chip_pins(void)
{
	struct port_config pin_conf;

	port_get_config_defaults(&pin_conf);

	/* Configure control pins as output. */
	pin_conf.direction  = PORT_PIN_DIR_OUTPUT;
	port_pin_set_config(CONF_WINC_PIN_RESET, &pin_conf);
	port_pin_set_config(CONF_WINC_PIN_CHIP_ENABLE, &pin_conf);
	port_pin_set_config(CONF_WINC_PIN_WAKE, &pin_conf);
	port_pin_set_output_level(CONF_WINC_PIN_CHIP_ENABLE, false);
	port_pin_set_output_level(CONF_WINC_PIN_RESET, false);
}
Пример #17
0
//! [setup]
int main(void)
{
	//! [setup_init]
	system_init();
	configure_ac();
	configure_ac_channel();
	configure_ac_callback();

	//! [setup_17]
	ac_enable(&ac_instance);
	//! [setup_17]
	//! [setup_init]

	//! [main]
	//! [main_1]
	ac_chan_trigger_single_shot(&ac_instance, AC_COMPARATOR_CHANNEL);
	//! [main_1]

	//! [main_2]
	uint8_t last_comparison = AC_CHAN_STATUS_UNKNOWN;
	//! [main_2]
	port_pin_set_output_level(LED_0_PIN, true);
	//! [main_3]
	while (true) {
	//! [main_3]
	//! [main_4]
		if (callback_status == true) {
	//! [main_4]
			//! [main_5]
			do
			{
				last_comparison = ac_chan_get_status(&ac_instance,
						AC_COMPARATOR_CHANNEL);
			} while (last_comparison & AC_CHAN_STATUS_UNKNOWN);
			//! [main_5]
			//! [main_6]
			port_pin_set_output_level(LED_0_PIN,
					(last_comparison & AC_CHAN_STATUS_NEG_ABOVE_POS));
			//! [main_6]
			//! [main_7]
			callback_status = false;
			//! [main_7]
			//! [main_8]
			ac_chan_trigger_single_shot(&ac_instance, AC_COMPARATOR_CHANNEL);
			//! [main_8]
		}
	}
	//! [main]
}
Пример #18
0
static void led_task (void *pvParameters)
{
	(void)pvParameters;

	for(;;)
	{
		
		vTaskDelay( 1000 );
		port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);
		vTaskDelay( 1000 );
		port_pin_set_output_level(LED_0_PIN, LED_0_INACTIVE);
	}
	/* Should never go there */
	vTaskDelete(worker1_id);
}
Пример #19
0
/**
 * \brief Application entry point.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	//SystemInit();
	
	// Set the registers for input and output
	board_led_setup();
	
	system_init();
	
	port_pin_set_output_level(LED_DEBUG, false);
	
	while ( !system_clock_source_is_ready(SYSTEM_CLOCK_SOURCE_DPLL) ) {
	}
	

	/* Initialize the SAM system */
	
	// TCC Configuration
	tcc_configure_function();		// Counter Configuration
	tcc_callback_configuration();	// Timer Callback Configuration
	
	// Run SERCOM Setup
	bastian_complete_sercom_setup();	

	system_interrupt_enable_global();	// Enable all sources of interrupt
	//spi_transceive_buffer_job(&spi_slave, slave_empty_response_buffer, slave_rx_buffer, SYSTEM_SLAVE_RX_BYTES_TO_RECEIVE);
	// Send IrDA data only once
	//
	//usart_read_buffer_job(&irda_master, slave_rx_buffer, 1);	// Read only one character
	
    while (1) {
		//usart_read_buffer_job(&irda_master, slave_rx_buffer, 1);	// Read only one character	
		
    }
}
Пример #20
0
int main(void)
{
//! [main_setup]
//! [system_init]
	system_init();
//! [system_init]
//! [run_config]
	configure_spi_master();
//! [run_config]
//! [main_setup]

//! [main_use_case]
//! [inf_loop]
	while (true) {
		/* Infinite loop */
		if(!port_pin_get_input_level(BUTTON_0_PIN)) {
			//! [select_slave]
			spi_select_slave(&spi_master_instance, &slave, true);
			//! [select_slave]
			//! [write]
			spi_write_buffer_wait(&spi_master_instance, buffer, BUF_LENGTH);
			//! [write]
			//! [deselect_slave]
			spi_select_slave(&spi_master_instance, &slave, false);
			//! [deselect_slave]
			//! [light_up]
			port_pin_set_output_level(LED_0_PIN, LED0_ACTIVE);
			//! [light_up]
		}
	}
//! [inf_loop]
//! [main_use_case]
}
Пример #21
0
/*---------------------------------------------------------------------------*/
static int
open(int32_t baudrate, uart_rx_char_callback char_cb, uart_rx_frame_callback frame_cb)
{
  struct usart_config config_usart;
  struct port_config pin_conf;

  usart_get_config_defaults(&config_usart);

  config_usart.baudrate    = baudrate;
  config_usart.mux_setting = RS485_SERCOM_MUX_SETTING;
  config_usart.pinmux_pad0 = RS485_SERCOM_PINMUX_PAD0;
  config_usart.pinmux_pad1 = RS485_SERCOM_PINMUX_PAD1;
  config_usart.pinmux_pad2 = RS485_SERCOM_PINMUX_PAD2;
  config_usart.pinmux_pad3 = RS485_SERCOM_PINMUX_PAD3;

  while (usart_init(&usart_instance, RS485_MODULE, &config_usart) != STATUS_OK) {}

  usart_enable(&usart_instance);

  port_get_config_defaults(&pin_conf);
  pin_conf.direction = PORT_PIN_DIR_OUTPUT;
  port_pin_set_config(RS485_TXE, &pin_conf);
  port_pin_set_output_level(RS485_TXE, false);

  char_callback = char_cb;

  usart_register_callback(&usart_instance,
                          usart_read_callback, USART_CALLBACK_BUFFER_RECEIVED);

  usart_enable_callback(&usart_instance, USART_CALLBACK_BUFFER_RECEIVED);

  usart_read_job(&usart_instance, &rx_char);

  return 1;
}
Пример #22
0
static void IIC_Init(void)
{
	IIC_SCL(1);
	IIC_SDA(1);
	
	port_get_config_defaults(&pin_clk);
	pin_clk.direction = PORT_PIN_DIR_OUTPUT;	
	port_pin_set_config(PIN_I2C_CLK, &pin_clk);
	port_pin_set_output_level(PIN_I2C_CLK, 1);

	port_get_config_defaults(&pin_data);
	pin_data.direction = PORT_PIN_DIR_OUTPUT;	
	port_pin_set_config(PIN_I2C_DATA, &pin_clk);
	port_pin_set_output_level(PIN_I2C_DATA, 1);
	
}
Пример #23
0
int main(void)
{
	system_init();
	delay_init();

	struct port_config pin;
	port_get_config_defaults(&pin);
	pin.direction = PORT_PIN_DIR_OUTPUT;

	port_pin_set_config(LED0_PIN, &pin);
	port_pin_set_output_level(LED0_PIN, LED0_INACTIVE);

	while (true) {
		for (int i = 0; i < 5; i++) {
			port_pin_toggle_output_level(LED0_PIN);
			delay_s(1);
		}

		for (int i = 0; i < 50; i++) {
			port_pin_toggle_output_level(LED0_PIN);
			delay_ms(100);
		}

		for (int i = 0; i < 5000; i++) {
			port_pin_toggle_output_level(LED0_PIN);
			delay_cycles(100);
		}
	}
}
Пример #24
0
int main(void)
{
    system_init();

    //! [setup_init]
    configure_extint_channel();
    //! [setup_init]

    //! [main]
    while (true) {
        //! [main_1]
        if (extint_chan_is_detected(BUTTON_0_EIC_LINE)) {
            //! [main_1]

            //! [main_2]
            // Do something in response to EXTINT edge detection
            bool button_pin_state = port_pin_get_input_level(BUTTON_0_PIN);
            port_pin_set_output_level(LED_0_PIN, button_pin_state);
            //! [main_2]

            //! [main_3]
            extint_chan_clear_detected(BUTTON_0_EIC_LINE);
            //! [main_3]
        }
    }
    //! [main]
}
Пример #25
0
/**
 * \brief Write data to the display controller
 *
 * This functions sets the pin D/C# before writing to the controller. Different
 * data write function is called based on the selected interface.
 *
 * \param data the data to write
 */
void ssd1306_write_data(uint8_t data)
{
	spi_select_slave(&ssd1306_master, &ssd1306_slave, true);
	port_pin_set_output_level(SSD1306_DC_PIN, true);
	spi_write_buffer_wait(&ssd1306_master, &data, 1);
	spi_select_slave(&ssd1306_master, &ssd1306_slave, false);
}
Пример #26
0
/**
 * \brief Writes a command to the display controller
 *
 * This functions pull pin D/C# low before writing to the controller. Different
 * data write function is called based on the selected interface.
 *
 * \param command the command to write
 */
void ssd1306_write_command(uint8_t command)
{
	spi_select_slave(&ssd1306_master, &ssd1306_slave, true);
	port_pin_set_output_level(SSD1306_DC_PIN, false);
	spi_write_buffer_wait(&ssd1306_master, &command, 1);
	spi_select_slave(&ssd1306_master, &ssd1306_slave, false);
}
Пример #27
0
/**
 * \brief main function : do init and loop
 */
int main(void)
{
	system_init();
	configure_console();
	delay_init();

	/* Turn on the backlight. */
	port_pin_set_output_level(SLCD_BACLKLIGHT,true);

	printf("Start SLCD test\r\n");
	/* Initialize the C42412A LCD glass component. */
	c42412a_init();

	c42412a_show_all();
	c42412a_set_contrast(0x8);
	delay_s(1);
	c42412a_clear_all();

	c42412a_icon_test();
	delay_s(1);
	c42412a_blink_test();
	delay_s(1);
	c42412a_text_test();
	delay_s(1);
	c42412a_num_dec_test();
	delay_s(1);
	c42412a_animation_test();
	while (1) {
	}
}
int main(void)
{
	system_init();

//! [setup_init]
	configure_eeprom();
//! [setup_init]

//! [main]
//! [read_page]
	uint8_t page_data[RWW_EEPROM_PAGE_SIZE];
	rww_eeprom_emulator_read_page(0, page_data);
//! [read_page]

//! [toggle_first_byte]
	page_data[0] = !page_data[0];
//! [toggle_first_byte]
//! [set_led]
	port_pin_set_output_level(LED_0_PIN, page_data[0]);
//! [set_led]

//! [write_page]
	rww_eeprom_emulator_write_page(0, page_data);
	rww_eeprom_emulator_commit_page_buffer();
//! [write_page]

	while (true) {

	}
//! [main]
}
Пример #29
0
void control_cmd_handler(void *pMsg)
{
	char *arg = (char *)pMsg;

	while (*arg == ' ') {
		arg++;
	}

	if (!strcmp(arg, "ledon")) {
		port_pin_set_output_level(LED_0_PIN, LED_0_ACTIVE);
	} else if (!strcmp(arg, "ledoff")) {
		port_pin_set_output_level(LED_0_PIN, LED_0_INACTIVE);
	} else {
		printf("Not supported remote command!\r\n");
	}
}
Пример #30
0
/**
 * \brief Initialize the OLED controller
 *
 * Call this function to initialize the hardware interface and the OLED
 * controller. When initialization is done the display is turned on and ready
 * to receive data.
 */
void ssd1306_init(void)
{
	// Initialize delay routine
	delay_init();
	// Do a hard reset of the OLED display controller
	ssd1306_hard_reset();

	// Initialize the interface
	ssd1306_interface_init();

	// Set the reset pin to the default state
	port_pin_set_output_level(SSD1306_RES_PIN, true);

	// 1/32 Duty (0x0F~0x3F)
	ssd1306_write_command(SSD1306_CMD_SET_MULTIPLEX_RATIO);
	ssd1306_write_command(0x1F);

	// Shift Mapping RAM Counter (0x00~0x3F)
	ssd1306_write_command(SSD1306_CMD_SET_DISPLAY_OFFSET);
	ssd1306_write_command(0x00);

	// Set Mapping RAM Display Start Line (0x00~0x3F)
	ssd1306_write_command(SSD1306_CMD_SET_DISPLAY_START_LINE(0x00));

	// Set Column Address 0 Mapped to SEG0
	ssd1306_write_command(SSD1306_CMD_SET_SEGMENT_RE_MAP_COL127_SEG0);

	// Set COM/Row Scan Scan from COM63 to 0
	ssd1306_write_command(SSD1306_CMD_SET_COM_OUTPUT_SCAN_DOWN);

	// Set COM Pins hardware configuration
	ssd1306_write_command(SSD1306_CMD_SET_COM_PINS);
	ssd1306_write_command(0x02);

	ssd1306_set_contrast(0x8F);

	// Disable Entire display On
	ssd1306_write_command(SSD1306_CMD_ENTIRE_DISPLAY_AND_GDDRAM_ON);

	ssd1306_display_invert_disable();

	// Set Display Clock Divide Ratio / Oscillator Frequency (Default => 0x80)
	ssd1306_write_command(SSD1306_CMD_SET_DISPLAY_CLOCK_DIVIDE_RATIO);
	ssd1306_write_command(0x80);

	// Enable charge pump regulator
	ssd1306_write_command(SSD1306_CMD_SET_CHARGE_PUMP_SETTING);
	ssd1306_write_command(0x14);

	// Set VCOMH Deselect Level
	ssd1306_write_command(SSD1306_CMD_SET_VCOMH_DESELECT_LEVEL);
	ssd1306_write_command(0x40); // Default => 0x20 (0.77*VCC)

	// Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
	ssd1306_write_command(SSD1306_CMD_SET_PRE_CHARGE_PERIOD);
	ssd1306_write_command(0xF1);

	ssd1306_display_on();
}