void bspI2cInit(void) { Semaphore_Params semParamsMutex; // Create protection semaphore Semaphore_Params_init(&semParamsMutex); semParamsMutex.mode = Semaphore_Mode_BINARY; Semaphore_construct(&mutex, 1, &semParamsMutex); // Reset the I2C controller HWREG(PRCM_BASE + PRCM_O_RESETI2C) = PRCM_RESETI2C_I2C; I2C_init(); I2C_Params_init(&I2CParams); I2CParams.bitRate = I2C_400kHz; I2Chandle = I2C_open(Board_I2C, &I2CParams); // Initialize local variables slaveAddr = 0xFF; interface = BSP_I2C_INTERFACE_0; #ifdef POWER_SAVING checkI2cConstraint = false; #endif /* if (I2Chandle == NULL) { while(1) { // wait here for ever } } */ }
/******************************************************************************* * @fn i2c_sel_interfas * @brief Selecciona interfas * @param Interfas - 0 o 1=MPU * @param dir - Esclavo * @return ok Siempre */ bool i2c_sel_interface(uint8_t Interface, uint8_t dir) { slaveAddr = dir; //Dispositivo esclavo if (Interface != interface) //no es la actual ya seleccionada? { interface = Interface; I2C_close(i2cHandle); //Cierra apertura actual, si la hay // Sets custom to NULL, selects I2C interface 0 I2C_Params_init(&i2cParams); // Assign I2C data/clock pins according to selected I2C interface 1 if (interface == 1) { //i2cParams.custom = (void*)&pinCfg1; //así lo hacen en el sensor tag i2cParams.custom = (uintptr_t)&pinCfg1; //Modifico para suprimir el warning de tipo, pues espera un puntero uint } // Re-open RTOS driver with new bus pin assignment i2cHandle = I2C_open(Board_I2C, &i2cParams); } return true; }
/******************************************************************************* * @fn bspI2cInit * * @brief Initialize the RTOS I2C driver (must be called only once) * * @param none * * @return none */ void bspI2cInit(void) { Semaphore_Params semParamsMutex; // Create protection semaphore Semaphore_Params_init(&semParamsMutex); semParamsMutex.mode = Semaphore_Mode_BINARY; Semaphore_construct(&mutex, 1, &semParamsMutex); // Reset the I2C controller HapiResetPeripheral(PRCM_PERIPH_I2C0); I2C_init(); I2C_Params_init(&i2cParams); i2cParams.bitRate = I2C_400kHz; i2cHandle = I2C_open(Board_I2C, &i2cParams); // Initialize local variables slaveAddr = 0xFF; interface = BSP_I2C_INTERFACE_0; if (i2cHandle == NULL) { Task_exit(); } }
/******************************************************************* * Function: void initializeRobot(void) * Input Variables: none * Output Return: none * Overview: This initialize the robot by using other startups ********************************************************************/ void initializeRobot(void) { ATopstat = ATTINY_open();//open the tiny microcontroller LEopstat = LED_open(); //open the LED module LCopstat = LCD_open(); //open the LCD module STEPPER_open(); // Open STEPPER module for use SPKR_open(SPKR_TONE_MODE);//open the speaker in tone mode LED_open(); I2C_open(); ADC_open();//open the ADC module ADC_set_VREF( ADC_VREF_AVCC );// Set the Voltage Reference first so VREF=5V. // Initialize IR Values and Reset Prefilter checkIR(); prefilter(1); // Mistake? odometryTrigger = WORLD_RESOLUTION_SIZE*D_STEP which is about 6 odometryTrigger = WORLD_RESOLUTION_SIZE/2.75; // pixel array for the LCD screen for(int i = 0; i < 4; i++) { for(int j = 0; j < 32; j++) { pix_arr[i][j] = 0x00; } } }
static PyObject *I2CDev_open(I2CDev *self, PyObject *args, PyObject *kwds) { uint8_t use_10bit_address; static char *kwlist[] = {"use_10bit_address", NULL}; use_10bit_address = 0; if(!PyArg_ParseTupleAndKeywords(args, kwds, "|b", kwlist, &use_10bit_address)) { return NULL; } if (self->i2c_fd > 0) I2C_close(self->i2c_fd); self->i2c_fd = I2C_open(self->bus_num); if (self->i2c_fd < 0) { PyErr_SetString(PyExc_IOError, "could not open I2C interface"); return NULL; } if (use_10bit_address) { if (I2C_enable10BitAddressing(self->i2c_fd) < 0) { PyErr_SetString(PyExc_IOError, "could not set I2C interface to 10-bit address mode"); return NULL; } } else { if (I2C_disable10BitAddressing(self->i2c_fd) < 0) { PyErr_SetString(PyExc_IOError, "could not set I2C interface to 10-bit address mode"); return NULL; } } Py_INCREF(Py_None); return Py_None; }
/* * ======== Board_openI2C ======== * Initialize the I2C driver. * Initialize the I2C port's pins. * Open the I2C port. */ I2C_Handle Board_openI2C(UInt i2cPortIndex, I2C_Params *i2cParams) { /* Initialize the I2C driver */ /* By design, I2C_init() is idempotent */ I2C_init(); /* initialize the pins associated with the respective I2C */ switch (i2cPortIndex) { case 0: /* * Configure LaunchPad P1.9 as a I2C pin: LaunchPad Sensor Data (via I2C) * device pin: 1 (I2C_SCL) * Wiring id : 9 */ MAP_PinTypeI2C(PIN_01, PIN_MODE_1); /* * Configure LaunchPad P1.10 as a I2C pin: LaunchPad Sensor Data (via I2C) * device pin: 2 (I2C_SDA) * Wiring id : 10 */ MAP_PinTypeI2C(PIN_02, PIN_MODE_1); break; default: return (NULL); } /* open the I2C */ return (I2C_open(i2cPortIndex, i2cParams)); }
/******************************************************************************* * @fn bspI2cSelect * * @brief Select an I2C interface and slave * * @param newInterface - selected interface * @param address - slave address * * @return true if success */ bool bspI2cSelect(uint8_t newInterface, uint8_t address) { // Acquire I2C resource if (!Semaphore_pend(Semaphore_handle(&mutex),MS_2_TICKS(I2C_TIMEOUT))) { return false; } // Store new slave address slaveAddr = address; // Interface changed ? if (newInterface != interface) { // Store new interface interface = newInterface; // Shut down RTOS driver I2C_close(i2cHandle); // Sets custom to NULL, selects I2C interface 0 I2C_Params_init(&i2cParams); // Assign I2C data/clock pins according to selected I2C interface 1 if (interface == BSP_I2C_INTERFACE_1) { i2cParams.custom = (void*)&pinCfg1; } // Re-open RTOS driver with new bus pin assignment i2cHandle = I2C_open(Board_I2C, &i2cParams); } return true; }
Uint32 TPS65070_open(Uint32 instance) { Uint32 status = E_PASS; switch(instance) { case 0: tpsConfigObj[0].i2cConfig.addrMode = I2C_ADDRESSING_7BIT; tpsConfigObj[0].i2cConfig.i2cclkh = DEVICE_I2C_CLKH; tpsConfigObj[0].i2cConfig.i2cclkl = DEVICE_I2C_CLKL; tpsConfigObj[0].i2cConfig.ownAddr = DEVICE_I2C_OWN_ADDRESS; tpsConfigObj[0].i2cConfig.prescalar = DEVICE_I2C_CLK_PRESCALE; tpsConfigObj[0].hI2cInfo = NULL; tpsConfigObj[0].hI2cInfo = \ I2C_open(0, I2C_ROLE_MASTER, I2C_MODE_AUTO_STOP, &tpsConfigObj[0].i2cConfig); status = (tpsConfigObj[0].hI2cInfo ? E_PASS : E_FAIL) ; if(status == E_PASS) { tpsConfigObj[0].hI2cInfo->slaveAddr = DEVICE_I2C_TPS65070_PMIC_SLAVE_ADDR; } break; default: status = E_FAIL; break; } return status; }
Void cycleLED(UArg arg0, UArg arg1) { unsigned int i = 0; uint8_t writeBuffer[4]; I2C_Handle handle; I2C_Params i2cparams; I2C_Transaction i2c; I2C_Params_init(&i2cparams); i2cparams.bitRate = I2C_400kHz; handle = I2C_open(Board_I2C_TPL0401, &i2cparams); if (handle == NULL) { System_abort("I2C was not opened"); } i2c.slaveAddress = Board_TPL0401_ADDR; i2c.readCount = 0; i2c.readBuf = NULL; i2c.writeBuf = writeBuffer; /* Enable the PWM oscillator */ writeBuffer[0] = 0x00; writeBuffer[1] = 0x81; i2c.writeCount = 2; if (!I2C_transfer(handle, &i2c)) { GPIO_write(Board_LED1, Board_LED_ON); System_abort("Bad I2C transfer!"); } /* Bring the LEDs into PWM mode */ writeBuffer[0] = 0x8C; writeBuffer[1] = 0xAA; writeBuffer[2] = 0xAA; i2c.writeCount = 3; if (!I2C_transfer(handle, &i2c)) { GPIO_write(Board_LED1, Board_LED_ON); System_abort("Bad I2C transfer!"); } i2c.writeCount = 4; while (true) { /* Point to the new LED pattern */ i2c.writeBuf = (uint8_t *) &(rgbcmd[i]); if (!I2C_transfer(handle, &i2c)) { GPIO_write(Board_LED1, Board_LED_ON); System_abort("Bad I2C transfer!"); } /* Reached the end of the RGB patterns; reset index */ if (rgbcmd[++i].LED == 0x00) { i = 0; } Task_sleep(100); } }
void CBOT_main( void ) { // Initialize variables int btnValue=0;//value of button pushed ATopstat = ATTINY_open();//open the tiny microcontroller LEopstat = LED_open(); //open the LED module LCopstat = LCD_open(); //open the LCD module STEPPER_open(); // Open STEPPER module for use SPKR_open(SPKR_BEEP_MODE);//open the speaker in beep mode LED_open(); I2C_open(); ADC_open();//open the ADC module ADC_set_VREF( ADC_VREF_AVCC );// Set the Voltage Reference first so VREF=5V. // Initialize IR Values and Reset Prefilter checkIR(); prefilter(1); // LCD_printf("PRESS a button\nOR\nWAIT for default\n"); //TMRSRVC_delay(3000);//wait 3 seconds //btnValue = WaitButton(); LCD_clear; // Infinite loop while (1) { // update the sensor values checkLightSensor(); checkIR(); checkContactIR(); //Test contact Sensors // LCD_printf("Right Contact: %i\nLeft Contact: %i\n\n\n",rightContact,leftContact); // TMRSRVC_delay(1000);//wait 1 seconds //Test IR Sensors // LCD_printf("FrontIR = %3.2f\nBackIR = %3.2f\nLeftIR = %3.2f\nRightIR = %3.2f\n", ftIR,bkIR,ltIR,rtIR); // TMRSRVC_delay(2000);//wait 2 seconds // run the moveBehavior FSM moveBehavior(LIGHT_LOVER); // debug primitive behaviors // moveAway(); // moveWall(); // moveRetreat(); // moveTrackLight(); // moveWander(); } }// end the CBOT_main()
void CBOT_main( void ) { // Initialize variables int btnValue=0;//value of button pushed int i=0;//loop counter BOOL ltContact;//left contact sensor BOOL rtContact;//right contact sensor float ltLght;//left light reading float rtLght;//right light reading unsigned char data; unsigned char pixel1 = 0; unsigned char pixel2 = 0; unsigned char pixel3 = 0; unsigned char pixel4 = 0; unsigned char pixel5 = 0; unsigned char pixel6 = 0; unsigned char pixel7 = 0; unsigned char pixel8 = 0; ATopstat = ATTINY_open();//open the tiny microcontroller LEopstat = LED_open(); //open the LED module LCopstat = LCD_open(); //open the LCD module STEPPER_open(); // Open STEPPER module for use. SPKR_open(SPKR_BEEP_MODE);//open the speaker in beep mode LED_open(); I2C_open(); ADC_open();//open the ADC module ADC_set_VREF( ADC_VREF_AVCC );// Set the Voltage Reference first so VREF=5V. btnValue = WaitButton(); // Infinite loop while (1) { // check sensors //checkIR(); // if no obstacle detected MOVE // if obstacle detected STOP // moveCollide(); moveAway(); } }// end the CBOT_main()
void HalI2CInit(void) { #ifdef TI_DRIVERS_I2C_INCLUDED Board_initI2C(); // Setup I2C and initialize the driver. I2C_Params_init(&I2CParams); I2CParams.bitRate = I2C_400kHz; I2Chandle = I2C_open(Board_I2C, &I2CParams); if (I2Chandle == NULL) { while(1) { // whait here for ever } } #endif }
/******************************************************************************* * @fn i2c_inicia * @brief Inicia i2c */ bool i2c_inicia(void) { I2C_init(); I2C_Params_init(&i2cParams); i2cParams.bitRate = I2C_400kHz; i2cHandle = I2C_open(Board_I2C, &i2cParams); slaveAddr = 0xFF; interface = 0; if (i2cHandle == NULL) { return false; } return true; }
void bspI2cSelect(uint8_t newInterface, uint8_t address) { /* Acquire I2C resource */ Semaphore_pend(Semaphore_handle(&mutex),BIOS_WAIT_FOREVER); #ifdef POWER_SAVING if (!checkI2cConstraint) { /* Prevent the system from entering standby while using I2C. */ Power_setConstraint(Power_SB_DISALLOW); checkI2cConstraint = true; } #endif slaveAddr = address; if (newInterface != interface) { interface = newInterface; I2C_close(I2Chandle); if (interface == BSP_I2C_INTERFACE_0) { i2cCC26xxHWAttrs[CC2650_I2C0].sdaPin = Board_I2C0_SDA0; i2cCC26xxHWAttrs[CC2650_I2C0].sclPin = Board_I2C0_SCL0; // Secondary I2C as GPIO IOCPinTypeGpioInput(Board_I2C0_SDA1); IOCPinTypeGpioInput(Board_I2C0_SCL1); IOCIOPortPullSet(Board_I2C0_SDA1, IOC_NO_IOPULL); IOCIOPortPullSet(Board_I2C0_SCL1, IOC_NO_IOPULL); } else if (interface == BSP_I2C_INTERFACE_1) { i2cCC26xxHWAttrs[CC2650_I2C0].sdaPin = Board_I2C0_SDA1; i2cCC26xxHWAttrs[CC2650_I2C0].sclPin = Board_I2C0_SCL1; // Primary I2C as GPIO IOCPinTypeGpioInput(Board_I2C0_SDA0); IOCPinTypeGpioInput(Board_I2C0_SCL0); IOCIOPortPullSet(Board_I2C0_SDA0, IOC_NO_IOPULL); IOCIOPortPullSet(Board_I2C0_SCL0, IOC_NO_IOPULL); } I2Chandle = I2C_open(Board_I2C, &I2CParams); } }
// Подключение кодека uint16 aic3204_open(void) { // Снять аппаратурный сброс кодека EBSR |= 0x0020; // Вывод A20 - GPIO[26] GPIO_DIR1 |= BIT10; // GPIO[26] - выход GPIO_OUT1 |= BIT10; // GPIO[26]=1 - снять сброс AIC3204 // Инициализация приборного интерфеса I2C_open(); // Подключить I2C // Инициализация звукового интерфеса PCGCR1 &= ~PCGCR1_I2S2CG; // Подать тактирование c5515_wait(100); // Ожидание завершения I2S2->SRATE = 0x15; // Синхронизация: кадров 32, бит 64 I2S2->INTMASK = INTFL_XMITL // Готовность стерео передатчика | INTFL_RCVL; // Готовность стерео приемника (0x0028) I2S2->SCTL = SCTL_ENABLE | SCTL_WDLNGTH16 | SCTL_MODE; c5515_wait(100); // Ожидание завершения инициализации return 0; }
Void Task_I2C(UArg arg0, UArg arg1) { I2C_Handle i2c; I2C_Params i2cParams; I2C_Transaction i2cTransaction; uint8_t txBuffer[4]; uint8_t rxBuffer[4]; I2C_Params_init(&i2cParams); i2cParams.bitRate = I2C_400kHz; i2cParams.transferMode = I2C_MODE_BLOCKING; i2c = I2C_open(Board_I2C_NFC, &i2cParams); if (i2c == NULL) { System_abort("Error Initializing I2C\n"); } else { System_printf("\nTask_I2C"); } i2cTransaction.slaveAddress = 0x17; for (;;) { i2cTransaction.writeBuf = txBuffer; i2cTransaction.writeCount = sizeof(txBuffer); i2cTransaction.readCount = 0; txBuffer[0]=1; txBuffer[1]=2; txBuffer[2]=3; txBuffer[3]=4; if (!I2C_transfer(i2c, &i2cTransaction)) { System_printf("Bad I2C transfer!"); } Task_sleep(200); //One Tick is 1ms } }
/******************************************************************************* * @fn bspI2cReset * * @brief Reset the RTOS I2C driver * * @param none * * @return none */ void bspI2cReset(void) { // Acquire I2C resource */ if (!Semaphore_pend(Semaphore_handle(&mutex),MS_2_TICKS(I2C_TIMEOUT))) { return; } // Close the driver I2C_close(i2cHandle); // Reset the I2C controller HapiResetPeripheral(PRCM_PERIPH_I2C0); // Reset local variables slaveAddr = 0xFF; interface = BSP_I2C_INTERFACE_0; // Open driver i2cHandle = I2C_open(Board_I2C, &i2cParams); // Release I2C resource Semaphore_post(Semaphore_handle(&mutex)); }
void CBOT_main( void ) { // Initialize Robot ATopstat = ATTINY_open();//open the tiny microcontroller LEopstat = LED_open(); //open the LED module LCopstat = LCD_open(); //open the LCD module STEPPER_open(); // Open STEPPER module for use SPKR_open(SPKR_BEEP_MODE);//open the speaker in beep mode LED_open(); I2C_open(); ADC_open();//open the ADC module ADC_set_VREF( ADC_VREF_AVCC );// Set the Voltage Reference first so VREF=5V. // // Print a debug statement // LCD_printf("It's ALIVE\n\n\n\n"); // TMRSRVC_delay(3000);//wait 3 seconds // LCD_clear(); // Print the metric Map // printMetricMap(); // LCD_printf("%i %i %i %i \n%i %i %i %i \n%i %i %i %i \n%i %i %i %i \n",ROBOT_METRIC_WORLD[0][0],ROBOT_METRIC_WORLD[0][1],ROBOT_METRIC_WORLD[0][2],ROBOT_METRIC_WORLD[0][3],ROBOT_METRIC_WORLD[1][0],ROBOT_METRIC_WORLD[1][1],ROBOT_METRIC_WORLD[1][2],ROBOT_METRIC_WORLD[1][3],ROBOT_METRIC_WORLD[2][0],ROBOT_METRIC_WORLD[2][1],ROBOT_METRIC_WORLD[2][2],ROBOT_METRIC_WORLD[2][3],ROBOT_METRIC_WORLD[3][0],ROBOT_METRIC_WORLD[3][1],ROBOT_METRIC_WORLD[3][2],ROBOT_METRIC_WORLD[3][3]); // TMRSRVC_delay(10000);//wait 10 seconds // wavefrontMake(); // LCD_printf("%i %i %i %i \n%i %i %i %i \n%i %i %i %i \n%i %i %i %i \n",ROBOT_METRIC_WORLD[0][0],ROBOT_METRIC_WORLD[0][1],ROBOT_METRIC_WORLD[0][2],ROBOT_METRIC_WORLD[0][3],ROBOT_METRIC_WORLD[1][0],ROBOT_METRIC_WORLD[1][1],ROBOT_METRIC_WORLD[1][2],ROBOT_METRIC_WORLD[1][3],ROBOT_METRIC_WORLD[2][0],ROBOT_METRIC_WORLD[2][1],ROBOT_METRIC_WORLD[2][2],ROBOT_METRIC_WORLD[2][3],ROBOT_METRIC_WORLD[3][0],ROBOT_METRIC_WORLD[3][1],ROBOT_METRIC_WORLD[3][2],ROBOT_METRIC_WORLD[3][3]); // TMRSRVC_delay(10000);//wait 10 seconds // LCD_clear(); // Test the 4-Neighbor search // LCD_printf("%i %i %i %i \n%i %i %i %i \n%i %i %i %i \n%i %i %i %i \n",ROBOT_METRIC_WORLD[0][0],ROBOT_METRIC_WORLD[0][1],ROBOT_METRIC_WORLD[0][2],ROBOT_METRIC_WORLD[0][3],ROBOT_METRIC_WORLD[1][0],ROBOT_METRIC_WORLD[1][1],ROBOT_METRIC_WORLD[1][2],ROBOT_METRIC_WORLD[1][3],ROBOT_METRIC_WORLD[2][0],ROBOT_METRIC_WORLD[2][1],ROBOT_METRIC_WORLD[2][2],ROBOT_METRIC_WORLD[2][3],ROBOT_METRIC_WORLD[3][0],ROBOT_METRIC_WORLD[3][1],ROBOT_METRIC_WORLD[3][2],ROBOT_METRIC_WORLD[3][3]); // TMRSRVC_delay(5000); // LCD_clear(); currentCellWorld = WORLD_CELL[0][0]; wavefrontMake(); while(currentCellWorld!=reachedEnd){ nextOrientation = fourNeighborSearch(currentCellWorld); metricMove(); moveMap(); currentCellWorld = shiftMap(currentCellWorld, currentMove, currentOrientation); } LCD_printf("LOOOOOOOOOOOOLZ"); TMRSRVC_delay(5000); LCD_clear(); // Unit test the function // sqrt function // int xDelta, yDelta; // float distance; // xDelta = abs(-3); // yDelta = abs(0); // distance = sqrt(((xDelta*xDelta)+(yDelta*yDelta))); // LCD_printf("xDel = %d\nyDel = %d\ndist = %f\n\n",xDelta,yDelta,distance); // TMRSRVC_delay(5000); // LCD_clear(); // cell values }// end the CBOT_main()
void bspI2cReset(void) { I2C_close(I2Chandle); I2Chandle = I2C_open(Board_I2C, &I2CParams); }