static error_code_t I2C_Config_Pins(i2c_port_t i2c_port) { //Dont use GPIO_Config, as it could have a post hook. error_code_t error = NO_ERROR; i2c_map_t i2c_pin = lpc17xx_i2c_map[i2c_port]; if ( (error = GPIO_Set_Func( &(i2c_pin.scl), i2c_pin.func ) ) != NO_ERROR ) { return error; } if ( (error = GPIO_Set_Func( &(i2c_pin.sda), i2c_pin.func ) ) != NO_ERROR ) { return error; } if ( (error = GPIO_Set_Mode( &(i2c_pin.scl) ) ) != NO_ERROR ) { return error; } if ( (error = GPIO_Set_Mode( &(i2c_pin.sda) ) ) != NO_ERROR ) { return error; } if ( (error = GPIO_Set_OpenDrain_Mode( &(i2c_pin.scl) ) ) != NO_ERROR ) { return error; } if ( (error = GPIO_Set_OpenDrain_Mode( &(i2c_pin.sda) ) ) != NO_ERROR ) { return error; } if ( (error = GPIO_Set_Direction( &(i2c_pin.scl) ) ) != NO_ERROR ) { return error; } if ( (error = GPIO_Set_Direction( &(i2c_pin.sda) ) ) != NO_ERROR ) { return error; } return error; }
/** * Initialisation for the Motor_Left package. * This will be called from Tasks_Init by default. */ void Motor_Left_Init(void) { /* Task initialisation */ Left_motor_direction_G = Off; Left_motor_speed_G = 0; Motor_Lf_Enc_Track = 0; GPIO_Set_Direction(LED_Pin_LfFd, GPIO_OUTPUT); GPIO_Write(LED_Pin_LfFd, GPIO_LOW); GPIO_Set_Direction(LED_Pin_LfBd, GPIO_OUTPUT); GPIO_Write(LED_Pin_LfBd, GPIO_LOW); GPIO_Set_Direction(Left_SW, GPIO_INPUT); Segment_Enable(displayC); Segment_Write(displayC, 0x0); Segment_Clear_Decimal(displayC); Segment_Enable(displayD); Segment_Write(displayD, 0x0); Segment_Clear_Decimal(displayD); }
int main(void){ RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOCEN, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1ENR_TIM2EN, ENABLE); GPIO_Set_Direction(GPIOA, 0x0001, 0x0000); GPIO_Set_Direction(GPIOC, 0x0000, 0x0300); // Set PA0 as EXTI0 input source SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI0 & SYSCFG_EXTICR1_EXTI0_PA; EXTI_Init(0, EXTI_Trigger_Rising, ENABLE); TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE); TIM_SetCompare1(TIM2, 100); TIM_Cmd(TIM2, ENABLE); NVIC_EnableIRQ(EXTI0_1_IRQn); // Enable NVIC EXTI0_1_IRQn channel NVIC_EnableIRQ(TIM2_IRQn); // Enable NVIC TIM2_IRQn channel while(1); }