void sj_i2c_close(i2c_connection conn) { struct i2c_state *c = (struct i2c_state *) conn; MAP_PRCMPeripheralClkDisable(PRCM_I2CA0, PRCM_RUN_MODE_CLK); MAP_PinModeSet(c->sda_pin, c->sda_pin_mode); MAP_PinConfigSet(c->sda_pin, c->sda_pin_strength, c->sda_pin_type); MAP_PinModeSet(c->scl_pin, c->scl_pin_mode); MAP_PinConfigSet(c->scl_pin, c->scl_pin_strength, c->scl_pin_type); free(c); }
i32 cc_set_default(struct soc_io_park *io_park_choice, u8 num_pins) { i32 loopcnt; if(NULL == io_park_choice) { return -1; } /* Park the IOs safely as specified by the application */ for(loopcnt = 0; loopcnt < num_pins; loopcnt++) { /* Change the pin mode to default MODE 1 */ MAP_PinModeSet(io_park_choice[loopcnt].pin_num, PIN_MODE_1); /* Change the drive strength and pin type to default */ MAP_PinConfigSet(io_park_choice[loopcnt].pin_num, (PIN_STRENGTH_2MA | PIN_STRENGTH_4MA), PIN_TYPE_STD); /* Set the PINs as input */ MAP_PinDirModeSet(io_park_choice[loopcnt].pin_num, PIN_DIR_MODE_IN); } return 0; }
/****************************************************************************** DEFINE PRIVATE FUNCTIONS ******************************************************************************/ STATIC void pin_obj_configure (const pin_obj_t *self) { // Skip all this if the pin is to be used in analog mode if (self->type != PYBPIN_ANALOG_TYPE) { // verify the alternate function pin_verify_af (self->af); // PIN_MODE_0 means it stays as a pin, else, another peripheral will take control of it if (self->af == PIN_MODE_0) { // enable the peripheral clock for the GPIO port of this pin switch (self->port) { case PORT_A0: MAP_PRCMPeripheralClkEnable(PRCM_GPIOA0, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); break; case PORT_A1: MAP_PRCMPeripheralClkEnable(PRCM_GPIOA1, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); break; case PORT_A2: MAP_PRCMPeripheralClkEnable(PRCM_GPIOA2, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); break; case PORT_A3: MAP_PRCMPeripheralClkEnable(PRCM_GPIOA3, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); break; default: break; } // configure the direction MAP_GPIODirModeSet(self->port, self->bit, self->mode); } // now set the alternate function, strenght and type MAP_PinModeSet (self->pin_num, self->af); } MAP_PinConfigSet(self->pin_num, self->strength, self->type); }
STATIC void pin_obj_configure (const pin_obj_t *self) { uint32_t type; if (self->mode == PIN_TYPE_ANALOG) { type = PIN_TYPE_ANALOG; } else { type = self->pull; uint32_t direction = self->mode; if (direction == PIN_TYPE_OD || direction == GPIO_DIR_MODE_ALT_OD) { direction = GPIO_DIR_MODE_OUT; type |= PIN_TYPE_OD; } if (self->mode != GPIO_DIR_MODE_ALT && self->mode != GPIO_DIR_MODE_ALT_OD) { // enable the peripheral clock for the GPIO port of this pin switch (self->port) { case PORT_A0: MAP_PRCMPeripheralClkEnable(PRCM_GPIOA0, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); break; case PORT_A1: MAP_PRCMPeripheralClkEnable(PRCM_GPIOA1, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); break; case PORT_A2: MAP_PRCMPeripheralClkEnable(PRCM_GPIOA2, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); break; case PORT_A3: MAP_PRCMPeripheralClkEnable(PRCM_GPIOA3, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK); break; default: break; } // set the pin value if (self->value) { MAP_GPIOPinWrite(self->port, self->bit, self->bit); } else { MAP_GPIOPinWrite(self->port, self->bit, 0); } // configure the direction MAP_GPIODirModeSet(self->port, self->bit, direction); } // now set the alternate function MAP_PinModeSet (self->pin_num, self->af); } MAP_PinConfigSet(self->pin_num, self->strength, type); }
//***************************************************************************** // //! Mandatory MCU Initialization Routine //! //! \param None //! //! \return None // //***************************************************************************** void MCUInit(void) { unsigned long ulRegVal; // // DIG DCDC NFET SEL and COT mode disable // HWREG(0x4402F010) = 0x30031820; HWREG(0x4402F00C) = 0x04000000; UtilsDelay(32000); // // ANA DCDC clock config // HWREG(0x4402F11C) = 0x099; HWREG(0x4402F11C) = 0x0AA; HWREG(0x4402F11C) = 0x1AA; // // PA DCDC clock config // HWREG(0x4402F124) = 0x099; HWREG(0x4402F124) = 0x0AA; HWREG(0x4402F124) = 0x1AA; // // Enable RTC // if(MAP_PRCMSysResetCauseGet()== PRCM_POWER_ON) { HWREG(0x4402F804) = 0x1; } // // TD Flash timing configurations in case of MCU WDT reset // if((HWREG(0x4402D00C) & 0xFF) == 0x00000005) { HWREG(0x400F707C) |= 0x01840082; HWREG(0x400F70C4)= 0x1; HWREG(0x400F70C4)= 0x0; } // // JTAG override for I2C in SWD mode // if(((HWREG(0x4402F0C8) & 0xFF) == 0x2)) { MAP_PinModeSet(PIN_19,PIN_MODE_2); MAP_PinModeSet(PIN_20,PIN_MODE_2); HWREG(0x4402E184) |= 0x1; } // // Take I2C semaphore,##IMPROTANT:REMOVE IN PG1.32 DEVICES## // ulRegVal = HWREG(COMMON_REG_BASE + COMMON_REG_O_I2C_Properties_Register); ulRegVal = (ulRegVal & ~0x3) | 0x1; HWREG(COMMON_REG_BASE + COMMON_REG_O_I2C_Properties_Register) = ulRegVal; // // Take GPIO semaphore##IMPROTANT:REMOVE IN PG1.32 DEVICES## // ulRegVal = HWREG(COMMON_REG_BASE + COMMON_REG_O_GPIO_properties_register); ulRegVal = (ulRegVal & ~0x3FF) | 0x155; HWREG(COMMON_REG_BASE + COMMON_REG_O_GPIO_properties_register) = ulRegVal; // // Change UART pins(55,57) mode to PIN_MODE_0 if they are in PIN_MODE_1(NWP mode) // if((MAP_PinModeGet(PIN_55)) == PIN_MODE_1) { MAP_PinModeSet(PIN_55,PIN_MODE_0); } if((MAP_PinModeGet(PIN_57)) == PIN_MODE_1) { MAP_PinModeSet(PIN_57,PIN_MODE_0); } // // Enable Peripheral Clocks // MAP_PRCMPeripheralClkEnable(PRCM_UARTA0, PRCM_RUN_MODE_CLK); // // Configure PIN_55 for UART0 UART0_TX // MAP_PinTypeUART(PIN_55, PIN_MODE_3); // // Configure PIN_57 for UART0 UART0_RX // MAP_PinTypeUART(PIN_57, PIN_MODE_3); InitTerm(); //set the parameters of uart0 }