Ejemplo n.º 1
0
float ina219_get_bus_power(const device_info_t *device_info) {
	const uint8_t i = device_info->slave_address & 0x0F;

	i2c_setup(device_info);

	return ((float)((int16_t)i2c_read_reg_uint16_delayus(INA219_REG_POWER, (uint32_t) INA219_READ_REG_DELAY_US)) * ina219_info[i].power_lsb);
}
Ejemplo n.º 2
0
int main(void)
{
	clock_setup();
	gpio_setup();
	usart_setup();
	i2c_setup();
	/*uint8_t data[1]={(0x4 << ACC_CTRL_REG1_A_ODR_SHIFT) | ACC_CTRL_REG1_A_XEN};*/
	uint8_t data[1]={0x97};
	write_i2c(I2C1, I2C_ACC_ADDR, ACC_CTRL_REG1_A, 1, data);
	data[0]=0x08;
	write_i2c(I2C1, I2C_ACC_ADDR, ACC_CTRL_REG4_A, 1, data);
	uint16_t acc_x;

	while (1) {

		read_i2c(I2C1, I2C_ACC_ADDR, ACC_STATUS, 1, data);
		/*my_usart_print_int(USART2, data[0]);*/
		read_i2c(I2C1, I2C_ACC_ADDR, ACC_OUT_X_L_A, 1, data);
		acc_x=data[0];
		read_i2c(I2C1, I2C_ACC_ADDR, ACC_OUT_X_H_A, 1, data);
		acc_x|=(data[0] << 8);
		my_usart_print_int(USART2, (int16_t) acc_x);
		//int i;
		//for (i = 0; i < 800000; i++)    /* Wait a bit. */
		//  __asm__("nop");
	}

	return 0;
}
Ejemplo n.º 3
0
void initialize(void){
	bluetooth_setup((long)115200);
	lcd_init(LCD_DISP_ON); /* initialize lcd, display on, cursor on */
	i2c_setup(0x02);
	sei(); // Enable interrupt
	_delay_ms(2000);
}
Ejemplo n.º 4
0
void platform_init()
{
	arm_setup();
	mmu_setup();
	tasks_setup();

	// Basic prerequisites for everything else
	miu_setup();
	power_setup();

	clock_setup();

	// Need interrupts for everything afterwards
	interrupt_setup();

	gpio_setup();

	// For scheduling/sleeping niceties
	timer_setup();
	event_setup();

	// Other devices
	uart_setup();
	i2c_setup();

	dma_setup();

	LeaveCriticalSection();

	displaypipe_init();
	framebuffer_setup();
	framebuffer_setdisplaytext(TRUE);
}
Ejemplo n.º 5
0
float ina219_get_shunt_current(const device_info_t *device_info) {
	const uint8_t i = device_info->slave_address & 0x0F;

	i2c_setup(device_info);

	return ((float)((int16_t)i2c_read_reg_uint16_delayus(INA219_REG_CURRENT, (uint32_t) INA219_READ_REG_DELAY_US)) * ina219_info[i].current_lsb);
}
Ejemplo n.º 6
0
static int setup_devices() {
	// Basic prerequisites for everything else
	miu_setup();
	power_setup();

	clock_setup();

	// Need interrupts for everything afterwards
	interrupt_setup();

//	gpio_setup(); // Not yet

	// For scheduling/sleeping niceties
	timer_setup();
	event_setup();
#ifndef CONFIG_IPHONE_4
	wdt_setup();
#endif

	// Other devices
	usb_shutdown();
#ifndef CONFIG_IPHONE_4
	uart_setup();
	i2c_setup();

	dma_setup();

	spi_setup();
#endif

	return 0;
}
Ejemplo n.º 7
0
static int setup_devices() {
	// Basic prerequisites for everything else
	miu_setup();
	power_setup();
	clock_setup();

	// Need interrupts for everything afterwards
	interrupt_setup();

	gpio_setup();

	// For scheduling/sleeping niceties
	timer_setup();
	event_setup();
	wdt_setup();

	// Other devices
	usb_shutdown();
	uart_setup();
	i2c_setup();

	dma_setup();

	spi_setup();

	return 0;
}
Ejemplo n.º 8
0
static void
i2c_operation_setup(uint8_t *write_buf, uint8_t write_len,
  uint8_t *read_buf,  uint8_t read_len, uint16_t addr)
{
  device.rx_len = read_len;
  device.rx_buffer = read_buf;
  device.tx_len = write_len;
  device.tx_buffer = write_buf;
  device.rx_tx_len = device.rx_len + device.tx_len;

  /* Disable controller */
  set_value(QUARKX1000_IC_ENABLE,
    QUARKX1000_IC_ENABLE_MASK, QUARKX1000_IC_ENABLE_SHIFT, 0);

  i2c_setup();

  /* Disable interrupts */
  write(QUARKX1000_IC_INTR_MASK, 0);

  /* Clear interrupts */
  read(QUARKX1000_IC_CLR_INTR);

  /* Set address of target slave */
  set_value(QUARKX1000_IC_TAR,
    QUARKX1000_IC_TAR_MASK, QUARKX1000_IC_TAR_SHIFT, addr);
}
Ejemplo n.º 9
0
void platform_init()
{
	arm_setup();
	mmu_setup();
	tasks_setup();

	// Basic prerequisites for everything else
	miu_setup();
	power_setup();

	clock_setup();

	// Need interrupts for everything afterwards
	interrupt_setup();

	gpio_setup();

	// For scheduling/sleeping niceties
	timer_setup();
	event_setup();

	// Other devices
	usb_shutdown();
	uart_setup();
	i2c_setup();

	// DMA currently f***s up. Need to check why. -- Bluerise
	// dma_setup();

	LeaveCriticalSection();

	framebuffer_hook(); // TODO: Remove once LCD implemented -- Ricky26
	framebuffer_setdisplaytext(TRUE);
}
Ejemplo n.º 10
0
float ina219_get_bus_voltage(const device_info_t *device_info) {
	int16_t value;

	i2c_setup(device_info);

	value = ina219_get_bus_voltage_raw(device_info);

	return ((float) value * (float) 0.001);
}
Ejemplo n.º 11
0
int16_t ina219_get_shunt_voltage_raw(const device_info_t *device_info) {
	int16_t voltage;

	i2c_setup(device_info);

	voltage = (int16_t) i2c_read_reg_uint16_delayus(INA219_REG_SHUNTVOLTAGE, (uint32_t) INA219_READ_REG_DELAY_US);

	return voltage;
}
Ejemplo n.º 12
0
void platform_init()
{
	arm_setup();
	mmu_setup();
	tasks_setup();

	// Basic prerequisites for everything else
	miu_setup();
	power_setup();

	clock_setup();

	// Need interrupts for everything afterwards
	interrupt_setup();
	
	gpio_setup();

	// For scheduling/sleeping niceties
	timer_setup();
	event_setup();
	wdt_setup();

	// Other devices
//	uart_setup();
	i2c_setup();

//	dma_setup();

	spi_setup();

	LeaveCriticalSection();

	aes_setup();

	nor_setup();
	syscfg_setup();
	images_setup();
	nvram_setup();

//	lcd_setup();
	framebuffer_hook();	// TODO: Remove once LCD implemented
	framebuffer_setup();

//	audiohw_init();

	framebuffer_setdisplaytext(TRUE);


	gpio_register_interrupt(BUTTONS_HOLD_IRQ, BUTTONS_HOLD_IRQTYPE, BUTTONS_HOLD_IRQLEVEL, BUTTONS_HOLD_IRQAUTOFLIP, gpio_test_handler, 0);
	gpio_interrupt_enable(BUTTONS_HOLD_IRQ);
	gpio_register_interrupt(BUTTONS_HOME_IRQ, BUTTONS_HOME_IRQTYPE, BUTTONS_HOME_IRQLEVEL, BUTTONS_HOME_IRQAUTOFLIP, gpio_test_handler, 1);
	gpio_interrupt_enable(BUTTONS_HOME_IRQ);
	gpio_register_interrupt(BUTTONS_VOLUP_IRQ, BUTTONS_VOLUP_IRQTYPE, BUTTONS_VOLUP_IRQLEVEL, BUTTONS_VOLUP_IRQAUTOFLIP, gpio_test_handler, 2);
	gpio_interrupt_enable(BUTTONS_VOLUP_IRQ);
	gpio_register_interrupt(BUTTONS_VOLDOWN_IRQ, BUTTONS_VOLDOWN_IRQTYPE, BUTTONS_VOLDOWN_IRQLEVEL, BUTTONS_VOLDOWN_IRQAUTOFLIP, gpio_test_handler, 3);
	gpio_interrupt_enable(BUTTONS_VOLDOWN_IRQ);
}
Ejemplo n.º 13
0
ina219_mode_t ina219_get_mode(const device_info_t *device_info) {
	uint16_t value;

	i2c_setup(device_info);

	value = i2c_read_reg_uint16(INA219_REG_CONFIG);
	value &= INA219_CONFIG_MODE_MASK;

	return (ina219_mode_t) value;
}
Ejemplo n.º 14
0
ina219_shunt_res_t ina219_get_shunt_res(const device_info_t *device_info) {
	uint16_t value;

	i2c_setup(device_info);

	value = i2c_read_reg_uint16(INA219_REG_CONFIG);
	value &= INA219_CONFIG_SADCRES_MASK;

	return (ina219_shunt_res_t) value;
}
Ejemplo n.º 15
0
ina219_gain_t ina219_get_gain(const device_info_t *device_info) {
	uint16_t value;

	i2c_setup(device_info);

	value = i2c_read_reg_uint16(INA219_REG_CONFIG);
	value &= INA219_CONFIG_GAIN_MASK;

	return (ina219_gain_t) value;
}
Ejemplo n.º 16
0
int16_t ina219_get_bus_voltage_raw(const device_info_t *device_info) {
	uint16_t voltage;

	i2c_setup(device_info);

	voltage = i2c_read_reg_uint16_delayus(INA219_REG_BUSVOLTAGE, (uint32_t) INA219_READ_REG_DELAY_US);
	voltage >>= 3;

	return ((int16_t) voltage * (int16_t) 4);
}
Ejemplo n.º 17
0
ina219_range_t ina219_get_range(const device_info_t *device_info) {
	uint16_t value;

	i2c_setup(device_info);

	value = i2c_read_reg_uint16(INA219_REG_CONFIG);
	value &= INA219_CONFIG_BVOLTAGERANGE_MASK;

	return (ina219_range_t) value;
}
Ejemplo n.º 18
0
/*
 * MAIN
 */
int main(int argc, char** argv) {

    // RA1 as DO
    LATA = 0;
    ADCON1 = 0x06;
    TRISA1 = 0;
    LATA1 = 1;

    // I2C configuration
    i2c_setup();

    unsigned char w;
    for(w=0;w<20;w++)
        I2C_Recv[w]=0;

    unsigned int temps = 25;
    unsigned char temp, length=0;
    while(1){
        LATA1 = ~LATA1;
        Delay10KTCYx(temps);
        check_interruptions();
        if (DataRdyI2C()==1) {
            temps += 25;
            temp = ReadI2C();
            //********************* Data reception from master by slave *********************
            do {
                while(DataRdyI2C()==0);        // WAIT UNTILL THE DATA IS TRANSMITTED FROM master
                I2C_Recv[length++]=getcI2C();  // save byte received
            }
            while(length!=20);
        }
    }

    //******************** write sequence from slave *******************************
    while(SSPSTATbits.S!=1); //wait untill STOP CONDITION

    //********************* Read the address sent by master from buffer **************
    while(DataRdyI2C()==0); //WAIT UNTILL THE DATA IS TRANSMITTED FROM master
    temp = ReadI2C();

    //********************* Slave transmission ************************************
    if(SSPSTAT & 0x04) //check if master is ready for reception
        while(putsI2C(I2C_Send));			// send the data to master

    //-------------TERMINATE COMMUNICATION FROM MASTER SIDE---------------
    CloseI2C(); //close I2C module
    
    while(1) {
        LATA1 = ~LATA1;
        Delay10KTCYx(100);
    }; //End of program


    return (EXIT_SUCCESS);
}
Ejemplo n.º 19
0
int hashlet_setup(const char *bus, unsigned int addr)
{
    int fd = i2c_setup(bus);

    i2c_acquire_bus(fd, addr);

    wakeup(fd);

    return fd;

}
Ejemplo n.º 20
0
void i2c_reset()
{
	// Cleanup after an I2C error
	for ( uint8_t ch = ISSI_I2C_FirstBus_define; ch < ISSI_I2C_Buses_define + ISSI_I2C_FirstBus_define; ch++ )
	{
		volatile I2C_Channel *channel = &( i2c_channels[ch - ISSI_I2C_FirstBus_define] );
		channel->status = I2C_AVAILABLE;
	}

	i2c_setup();
}
Ejemplo n.º 21
0
/*******************************************
 * Main
 */
int main(void)
{
    uint32_t i;
    uint8_t d1 = 0;
    int8_t delta = +1; // Step for testing

    clock_init();
    gpio_setup();
    tim_setup();
    i2c_setup();
    lcd_init();

    lcd_seekto(1, 0 );
    lcd_writes("................");

    while (1) {
        // Blink
        gpio_toggle(GPIOB, GPIO1);

        // Put chars to LCD
        //lcd_putchar(' ' + d1);
        lcd_home();
        lcd_writes("Count ");
        lcd_write_uint(d1, 3);

        if( d1 % 10 == 0 )
        {
            lcd_seekto(1, d1 / 10 );
            lcd_writes(".<^^>.");
        }

        // Spinwait s bit
        for (i = 0; i < ( 20 * 72000 ); i++)
        {
            __asm__("nop");
        }

        // Sweep PWM
        d1 += delta;

        // Pingpong
        if( d1 >= 100 )
            delta = -1;
        else if( d1 <= 0 )
            delta = +1;

        pwm_set( d1 );
    }

    // Never reached
    return 0;
}
Ejemplo n.º 22
0
void setup(void)
{
    led_setup();

    serial_setup();
    interrupt_setup();
    i2c_setup();

    INTCON3bits.INT2IF = 0;

    //Print a welcome message in case someone plugs it up
    printf("Welcome to the RVAsec Badge!\n\r\n\r");
}
Ejemplo n.º 23
0
int main(void){

	if(i2c_setup(0x23) < 0){
		printf("err");
	}
	i2c_set_slave(0x27);
	i2c_write8(0x27, 0x00, 0x00);
	sleep(1);
	i2c_write8(0x27, 0x06, 0x00);
	sleep(1);
	i2c_write8(0x27, 0x0A, 0xff);
	sleep(1);
	i2c_write8(0x27, 0x09, 0xf0);
	return 0;
}
Ejemplo n.º 24
0
void platform_init()
{
	arm_setup();
	mmu_setup();
	tasks_setup();

	// Basic prerequisites for everything else
	miu_setup();
	power_setup();

	clock_setup();

	// Need interrupts for everything afterwards
	interrupt_setup();
	
	gpio_setup();

	// For scheduling/sleeping niceties
	timer_setup();
	event_setup();
	wdt_setup();

	// Other devices
	uart_setup();
	i2c_setup();

//	dma_setup();

	spi_setup();

	LeaveCriticalSection();

	aes_setup();

	displaypipe_init();
	framebuffer_setup();
	framebuffer_setdisplaytext(TRUE);
	lcd_set_backlight_level(186);

//	audiohw_init();
	
	//TODO: remove
	task_init(&iboot_loader_task, "iboot loader", TASK_DEFAULT_STACK_SIZE);
	task_start(&iboot_loader_task, &iboot_loader_run, NULL);
}
Ejemplo n.º 25
0
int main(void)
{
	int i = 0;
	uint16_t temperature;

	rcc_clock_setup_in_hse_16mhz_out_72mhz();
	gpio_setup();
	usart_setup();
	i2c_setup();

	gpio_clear(GPIOB, GPIO7);	/* LED1 on */
	gpio_set(GPIOB, GPIO6);		/* LED2 off */

	/* Send a message on USART1. */
	usart_send(USART1, 's');
	usart_send(USART1, 't');
	usart_send(USART1, 'm');
	usart_send(USART1, '\r');
	usart_send(USART1, '\n');

	stts75_write_config(I2C2, STTS75_SENSOR0);
	stts75_write_temp_os(I2C2, STTS75_SENSOR0, 0x1a00); /* 26 degrees */
	stts75_write_temp_hyst(I2C2, STTS75_SENSOR0, 0x1a00);
	temperature = stts75_read_temperature(I2C2, STTS75_SENSOR0);

	/* Send the temperature as binary over USART1. */
	for (i = 15; i >= 0; i--) {
		if (temperature & (1 << i))
			usart_send(USART1, '1');
		else
			usart_send(USART1, '0');
	}

	usart_send(USART1, '\r');
	usart_send(USART1, '\n');

	gpio_clear(GPIOB, GPIO6); /* LED2 on */

	while (1); /* Halt. */

	return 0;
}
Ejemplo n.º 26
0
int i2c_main(int argc, char *argv[])
#endif
{
  /* Verify settings */

  if (g_i2ctool.bus < CONFIG_I2CTOOL_MINBUS ||
      g_i2ctool.bus > CONFIG_I2CTOOL_MAXBUS)
    {
      g_i2ctool.bus = CONFIG_I2CTOOL_MINBUS;
    }

  if (g_i2ctool.addr < CONFIG_I2CTOOL_MINADDR ||
      g_i2ctool.addr > CONFIG_I2CTOOL_MAXADDR)
    {
      g_i2ctool.addr = CONFIG_I2CTOOL_MINADDR;
    }

  if (g_i2ctool.regaddr < CONFIG_I2CTOOL_MAXREGADDR)
    {
      g_i2ctool.regaddr = 0;
    }

  if (g_i2ctool.width != 8 && g_i2ctool.width != 16)
    {
      g_i2ctool.width = 8;
    }

  if (g_i2ctool.freq == 0)
    {
      g_i2ctool.freq = CONFIG_I2CTOOL_DEFFREQ;
    }

  /* Parse and process the command line */

  i2c_setup(&g_i2ctool);
  (void)i2c_parse(&g_i2ctool, argc, argv);

  i2ctool_flush(&g_i2ctool);
  i2c_teardown(&g_i2ctool);
  return OK;
}
Ejemplo n.º 27
0
bool ina219_start(device_info_t *device_info) {
	i2c_begin();

	if (device_info->slave_address == (uint8_t) 0) {
		device_info->slave_address = INA219_I2C_DEFAULT_SLAVE_ADDRESS;
	}

	if (device_info->speed_hz == (uint32_t) 0) {
		device_info->fast_mode = true;
	}

	i2c_setup(device_info);

	if (!i2c_is_connected(device_info->slave_address)) {
		return false;
	}

	ina219_configure(device_info, INA219_RANGE_32V, INA219_GAIN_320MV, INA219_BUS_RES_12BIT, INA219_SHUNT_RES_12BIT_1S , INA219_MODE_SHUNT_BUS_CONT);

	ina219_calibrate(device_info, 0.1, 2);

	return true;
}
Ejemplo n.º 28
0
uint16_t ina219_get_calibration(const device_info_t *device_info) {
	i2c_setup(device_info);

	return i2c_read_reg_uint16(INA219_REG_CALIBRATION);
}
Ejemplo n.º 29
0
void si7005_setup(){
	i2c_setup();
	i2c_set_addr7(DEVID);
}
Ejemplo n.º 30
0
// Setup
inline void LED_setup()
{
	// Register Scan CLI dictionary
	CLI_registerDictionary( ledCLIDict, ledCLIDictName );
#if Storage_Enable_define == 1
	Storage_registerModule(&LedStorage);
#endif

	// Zero out FPS time
	LED_timePrev = Time_now();

	// Initialize framerate
	LED_framerate = ISSI_FrameRate_ms_define;

	// Global brightness setting
	LED_brightness = ISSI_Global_Brightness_define;

	// Initialize I2C error counters
	i2c_initial();

	// Initialize I2C
	i2c_setup();

	// Setup LED_pageBuffer addresses and brightness section
	LED_pageBuffer[0].i2c_addr = LED_MapCh1_Addr_define;
	LED_pageBuffer[0].reg_addr = ISSI_LEDPwmRegStart;
#if ISSI_Chips_define >= 2
	LED_pageBuffer[1].i2c_addr = LED_MapCh2_Addr_define;
	LED_pageBuffer[1].reg_addr = ISSI_LEDPwmRegStart;
#endif
#if ISSI_Chips_define >= 3
	LED_pageBuffer[2].i2c_addr = LED_MapCh3_Addr_define;
	LED_pageBuffer[2].reg_addr = ISSI_LEDPwmRegStart;
#endif
#if ISSI_Chips_define >= 4
	LED_pageBuffer[3].i2c_addr = LED_MapCh4_Addr_define;
	LED_pageBuffer[3].reg_addr = ISSI_LEDPwmRegStart;
#endif

	// Brightness emulation
#if ISSI_Chip_31FL3731_define
	// Setup LED_pageBuffer addresses and brightness section
	LED_pageBuffer_brightness[0].i2c_addr = LED_MapCh1_Addr_define;
	LED_pageBuffer_brightness[0].reg_addr = ISSI_LEDPwmRegStart;
#if ISSI_Chips_define >= 2
	LED_pageBuffer_brightness[1].i2c_addr = LED_MapCh2_Addr_define;
	LED_pageBuffer_brightness[1].reg_addr = ISSI_LEDPwmRegStart;
#endif
#if ISSI_Chips_define >= 3
	LED_pageBuffer_brightness[2].i2c_addr = LED_MapCh3_Addr_define;
	LED_pageBuffer_brightness[2].reg_addr = ISSI_LEDPwmRegStart;
#endif
#if ISSI_Chips_define >= 4
	LED_pageBuffer_brightness[3].i2c_addr = LED_MapCh4_Addr_define;
	LED_pageBuffer_brightness[3].reg_addr = ISSI_LEDPwmRegStart;
#endif
#endif

	// LED default setting
	LED_enable = ISSI_Enable_define;
	LED_enable_current = ISSI_Enable_define; // Needs a default setting, almost always unset immediately

	// Enable Hardware shutdown (pull low)
	GPIO_Ctrl( hardware_shutdown_pin, GPIO_Type_DriveSetup, GPIO_Config_Pullup );
	GPIO_Ctrl( hardware_shutdown_pin, GPIO_Type_DriveLow, GPIO_Config_Pullup );

#if ISSI_Chip_31FL3733_define == 1 || ISSI_Chip_31FL3736_define == 1
	// Reset I2C bus (pull high, then low)
	// NOTE: This GPIO may be shared with the debug LED
	GPIO_Ctrl( iirst_pin, GPIO_Type_DriveSetup, GPIO_Config_Pullup );
	GPIO_Ctrl( iirst_pin, GPIO_Type_DriveHigh, GPIO_Config_Pullup );
	delay_us(50);
	GPIO_Ctrl( iirst_pin, GPIO_Type_DriveLow, GPIO_Config_Pullup );
#endif

	// Zero out Frame Registers
	// This needs to be done before disabling the hardware shutdown (or the leds will do undefined things)
	LED_zeroControlPages();

	// Disable Hardware shutdown of ISSI chips (pull high)
	if ( LED_enable && LED_enable_current )
	{
		GPIO_Ctrl( hardware_shutdown_pin, GPIO_Type_DriveHigh, GPIO_Config_Pullup );
	}

	// Reset LED sequencing
	LED_reset();

	// Allocate latency resource
	ledLatencyResource = Latency_add_resource("ISSILed", LatencyOption_Ticks);
}