├── BSP_CR4000.h ├── BSP_CR5000.h ├── Radio Drivers ├── Pioneer.c ├── Pioneer.h ├── RadioFunctions.h ├── Sony.h ├── JVC.h ├── Clarion.h ├── Alpine.h ├── Kenwood.h ├── RadioFunctions.c └── Clarion.c ├── aes.c ├── TMP101.c ├── TMP108.c ├── TDA7718N.c ├── TDA7721.c ├── SigmaStudioFW.h ├── ascii_to_hex.h ├── Vehicle Drivers ├── ChimeStatus.h ├── DimmerInformation.h ├── SWC_DualFunction.h ├── NCA_IntegratedRadioChassis.h ├── ServiceTools.c ├── CAN_Handler.h ├── Doors.h ├── ServiceTools.h ├── NCA_From_SDAR.h ├── SWC.h ├── CAN_Activity.h ├── CAN_Autobaud.h ├── ArbTextDisplayLineAttributes.h ├── Brake.h ├── DiagnosticTool.h ├── TOYOTA_CAN_ID.h ├── VIN.h ├── CAN_TransceiverMS.h ├── Rap.h ├── MERCEDES_CAN_ID.h ├── InfotainmentAllowed.h ├── VW_CAN_ID.h ├── ClimateControlStataus.c ├── ClimateControlStatus.h ├── GMLAN_CAN_ID_V2.h ├── ChimeStatus.c ├── NCA_IntegratedRadioChassis.c ├── TurnSignals.h ├── VehicleSpeed.h ├── SWC_SendDelayed.h ├── DimmerInformation.c ├── CAN_TransceiverMS.c ├── CAN_TransceiverGMLAN.h ├── CAN_Activity.c ├── CAN_TransceiverFD.h ├── AudioSourceStatus.h ├── GearInformation.h ├── AudioMasterCommand.h ├── CAN_TransceiverLSFT.h ├── Brake.c ├── AdvancedRemoteReceiverControl.h ├── MirrorMovementRequest.h ├── GearInformation.c ├── CAN_Handler.c ├── Lighting.h ├── ArbTextDisplayStatus.h ├── CAN_MessageDelayed.h ├── DiagnosticTool.c ├── Doors.c ├── CAN_BufferV3.h ├── RemoteReceiverStatus.h ├── ChimeCommand.h ├── AudioAmplifierStatus.h ├── InfotainmentAllowed.c ├── CAN_BufferV2.h ├── CHRYSLER_Defines.h ├── Lighting.c ├── ArbTextReqSetDispParameter.h ├── VIN.c ├── FORD_CAN_ID.h ├── NCA_From_SDAR.c ├── VehicleSpeed.c ├── Rap.c ├── ArbTextReqSetDisplayText.h ├── CAN_TransceiverLSFT.c ├── ArbTextDisplayLineAttributes.c ├── SWC_SendDelayed.c ├── CAN_bufferV3.c └── CAN_Autobaud.c ├── HC4052_Control.h ├── callback.h ├── FSAV331_Control.h ├── RotaryEncoder.h ├── kickTheDog.h ├── README.md ├── Xilinx ├── I2C_Init.h ├── Uart_Init.h ├── Timer_Init.h ├── Peripherals_Init.h ├── InterruptController_Init.h ├── UartOut.h ├── SPI_ReadWrite.h ├── SPI_Init.h ├── GPIO_ReadWrite.h ├── PI3USB32212.h ├── I2C_ReadWrite.h ├── GPIO_Init.h ├── GPIO_ReadWrite.c ├── UartOut.c ├── Peripherals_Init.c ├── InterruptHandlers.h ├── TUSB1002.h ├── InterruptController_Init.c └── SPI_ReadWrite.c ├── TI ├── GPIO_Config.h ├── I2C0_Config.h ├── PWM_Config.h ├── SystemTick_Config.h ├── SystemClock_Config.h ├── ADC0_Config.h ├── Timer_Config.h ├── SystemTick_Config.c ├── SystemClock_Config.c ├── PeripheralsInit.h ├── PWM_Config.c ├── UART_Config.h ├── I2C0_Config.c ├── IRQ_Handler.h ├── I2C_TM4C.h └── Timer_Config.c ├── Sleep.h ├── CharArrayToInt.h ├── I2C_ISR_Callback_STM32.h ├── ChartoByte.h ├── TimerDelay.h ├── .gitignore ├── CanBusActivity.h ├── NotifyUserDMA.h ├── revision.h ├── TTP229-LSF.h ├── FloatToString.h ├── CommandList_Array.h ├── IsHex.h ├── USB_Buffer.h ├── Modulo256Checksum.h ├── ITOA.h ├── TCA9546A_Handler.h ├── TemperatureConversion.h ├── UART_Handler_STM32.h ├── Linear_5_11.h ├── I2C_Message_Handler.h ├── DebugMode.h ├── RotaryEncoder.c ├── Chksum16bit.h ├── StringManip.h ├── SystemTick_Handler_STM32.h ├── TemperatureConversion.c ├── TTP229-LSF.c ├── AssertParam.h ├── NotifyUser.h ├── CAN_Filter.h ├── INA3221_Handler.h ├── SigmaStudioFW.c ├── CharArrayToInt.c ├── TCA9546A.c ├── CommandList_Array.c ├── IsHex.c ├── LTM46xx_Handler.h ├── MAX_31760.c ├── TCA9546A.h ├── CharToByte.c ├── ChimeGenerator.h ├── RingBuff.h ├── UART_Handler_TM4C.h ├── CanBusActivity.c ├── UART_Handler_dsPIC33.h ├── AssertParam.c ├── ascii_to_hex.c ├── HC4052_Control.c ├── FSAV331_Control.c ├── TCA9546A_Handler.c ├── MCDP6200_I2C_ReadWrite.h ├── NotifyUserDMA.c ├── I2C_Message_Handler.c ├── STM32_UID.h ├── TMP10x_Handler.h ├── ErrorStatus.h ├── TCA9546A_Drv.c ├── DebugMode.c ├── ADC_Buffer_Handler_STM32.h ├── INA3221_Drv.c ├── TCA9546A_Drv.h ├── STM32_UID.c ├── CANFD_Buffer.h ├── FDCAN_Handler.h ├── RingBuffer.h ├── Interpolation_Drv.h ├── Modulo256Checksum.c ├── TMP10x_Drv.c ├── SystemTick_Handler_STM32.c ├── NotifyUser.c ├── kickTheDog.c ├── I2C_Drv_TM4C.h ├── UART_Handler.h ├── Flash_ReadWrite_Drv_STM32.h ├── I2C_Generic_Handler.h ├── GPIO_Ports.h ├── USB_CDC_Buffer.h ├── I2C_ISR_Callback_STM32.c ├── CommandList_Drv.h ├── Chksum16bit.c ├── I2C_Queue_STM32.h ├── Flash_ReadWrite_Drv_STM32.c ├── TUSB1002.h ├── ErrorStatus.c ├── UART_DMA_Handler_STM32.h ├── CAN_Filter.c ├── CAN_Buffer.h ├── Sleep.c ├── Flash_Data_Handler.h ├── PollingRoutine.h ├── RingBuffer.c ├── UART_Handler_STM32.c ├── I2C_GenericHandler_STM32.h ├── USB_CAN_Convert.h ├── UART_Handler_dsPIC33.c └── I2C_Generic_Handler_TM4C.h /BSP_CR4000.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /BSP_CR5000.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Radio Drivers/Pioneer.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Radio Drivers/Pioneer.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /aes.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlyamashita/common_libraries/HEAD/aes.c -------------------------------------------------------------------------------- /TMP101.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlyamashita/common_libraries/HEAD/TMP101.c -------------------------------------------------------------------------------- /TMP108.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlyamashita/common_libraries/HEAD/TMP108.c -------------------------------------------------------------------------------- /TDA7718N.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlyamashita/common_libraries/HEAD/TDA7718N.c -------------------------------------------------------------------------------- /TDA7721.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlyamashita/common_libraries/HEAD/TDA7721.c -------------------------------------------------------------------------------- /SigmaStudioFW.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karlyamashita/common_libraries/HEAD/SigmaStudioFW.h -------------------------------------------------------------------------------- /ascii_to_hex.h: -------------------------------------------------------------------------------- 1 | #ifndef ASCII_TO_HEX_H 2 | #define ASCII_TO_HEX_H 3 | 4 | 5 | int AscII2hex(char input, uint8_t *output); 6 | 7 | #endif // ASCII_TO_HEX_H 8 | -------------------------------------------------------------------------------- /Vehicle Drivers/ChimeStatus.h: -------------------------------------------------------------------------------- 1 | #ifndef CHIME_STATUS_H 2 | #define CHIME_STATUS_H 3 | 4 | 5 | void SendChimeStatus(bool status) ; 6 | 7 | #endif // CHIME_STATUS_H 8 | -------------------------------------------------------------------------------- /HC4052_Control.h: -------------------------------------------------------------------------------- 1 | #ifndef HC4052_CONTROL_H 2 | #define HC4052_CONTROL_H 3 | 4 | 5 | void SetVideoOutput(uint8_t videoOuput); 6 | 7 | 8 | #endif // HC4052_CONTROL_H 9 | -------------------------------------------------------------------------------- /callback.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CALL_BACK_H 3 | #define CALL_BACK_H 4 | 5 | // regular typedef callback passing a int value 6 | typedef void (*Callback)(int); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /FSAV331_Control.h: -------------------------------------------------------------------------------- 1 | #ifndef FSAV331_CONTROL_H 2 | #define FSAV331_CONTROL_H 3 | 4 | 5 | 6 | void SetAnalogOutput(uint8_t analogOuput); 7 | 8 | 9 | #endif // FSAV331_CONTROL_H 10 | -------------------------------------------------------------------------------- /RotaryEncoder.h: -------------------------------------------------------------------------------- 1 | #ifndef ROTARY_ENCODER_H 2 | #define ROTARY_ENCODER_H 3 | 4 | 5 | void RotaryEncoderCountUpdate(void); 6 | uint16_t GetRotaryEncoderCount(void); 7 | 8 | #endif // ROTARY_ENCODER_H 9 | -------------------------------------------------------------------------------- /kickTheDog.h: -------------------------------------------------------------------------------- 1 | #ifndef KICK_THE_DOG_H 2 | #define KICK_THE_DOG_H 3 | 4 | 5 | void KickTheDog(void); 6 | uint32_t TimeoutCalculation(uint32_t timevalue); 7 | 8 | #endif // KICK_THE_DOG_H 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | This is my common files that i link to for my past projects and for my future projects. 3 | 4 | Check out the wiki for more information https://github.com/karlyamashita/common_libraries/wiki 5 | -------------------------------------------------------------------------------- /Vehicle Drivers/DimmerInformation.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef DIMMER_INFORMATION_H 3 | #define DIMMER_INFORMATION_H 4 | 5 | void ServiceDimmer(uint8_t *data); 6 | uint8_t GetDimmerValue(void); 7 | 8 | #endif // DIMMER_INFORMATION_H 9 | -------------------------------------------------------------------------------- /Vehicle Drivers/SWC_DualFunction.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SWC_DUAL_FUNCTION_H 3 | #define SWC_DUAL_FUNCTION_H 4 | 5 | #include "main.h" 6 | 7 | uint8_t GetDualSWC_ButtonStatus(uint8_t command); 8 | 9 | #endif // SWC_DUAL_FUNCTION_H 10 | -------------------------------------------------------------------------------- /Vehicle Drivers/NCA_IntegratedRadioChassis.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef NCA_INTEGRATED_RADIO_CHASSIS_H 3 | #define NCA_INTEGRATED_RADIO_CHASSIS_H 4 | 5 | void SendNCA_IntegratedRadioChassis(void); 6 | 7 | 8 | 9 | #endif // NCA_INTEGRATED_RADIO_CHASSIS_H 10 | -------------------------------------------------------------------------------- /Vehicle Drivers/ServiceTools.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_SERVICE_TOOLS 3 | #include "main.h" 4 | #include "ServiceTools.h" 5 | 6 | 7 | void ServiceTechTool(uint8_t *data) { 8 | 9 | } 10 | 11 | 12 | 13 | #endif // USE_SERVICE_TOOLS 14 | -------------------------------------------------------------------------------- /Vehicle Drivers/CAN_Handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CAN_Handler.h 3 | * 4 | * Created on: Jan 7, 2023 5 | * Author: codek 6 | */ 7 | 8 | #ifndef INC_CAN_HANDLER_H_ 9 | #define INC_CAN_HANDLER_H_ 10 | 11 | 12 | 13 | #endif /* INC_CAN_HANDLER_H_ */ 14 | -------------------------------------------------------------------------------- /Vehicle Drivers/Doors.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef DOORS_H 3 | #define DOORS_H 4 | 5 | 6 | void ServiceDriversDoorStatus(unsigned char *data); 7 | void ServicePassengerDoorStatus(unsigned char *data); 8 | bool GetDriversDoorStatus(void); 9 | 10 | #endif // DOORS_H 11 | -------------------------------------------------------------------------------- /Xilinx/I2C_Init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * I2C_Init.h 3 | * 4 | * Created on: Jun 4, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SRC_I2C_INIT_H_ 9 | #define SRC_I2C_INIT_H_ 10 | 11 | int I2C_Init(void); 12 | 13 | #endif /* SRC_I2C_INIT_H_ */ 14 | -------------------------------------------------------------------------------- /Xilinx/Uart_Init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Uart_Init.h 3 | * 4 | * Created on: Jun 4, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SRC_UART_INIT_H_ 9 | #define SRC_UART_INIT_H_ 10 | 11 | int Init_Uart0(void); 12 | 13 | #endif /* SRC_UART_INIT_H_ */ 14 | -------------------------------------------------------------------------------- /Xilinx/Timer_Init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Timer_Init.h 3 | * 4 | * Created on: Jun 4, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SRC_TIMER_INIT_H_ 9 | #define SRC_TIMER_INIT_H_ 10 | 11 | int Init_Timer(void); 12 | 13 | #endif /* SRC_TIMER_INIT_H_ */ 14 | -------------------------------------------------------------------------------- /TI/GPIO_Config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GPIO_Config.h 3 | * 4 | * Created on: Jul 12, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef GPIO_CONFIG_H_ 9 | #define GPIO_CONFIG_H_ 10 | 11 | 12 | void GPIO_Config(void); 13 | 14 | 15 | #endif /* GPIO_CONFIG_H_ */ 16 | -------------------------------------------------------------------------------- /TI/I2C0_Config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * I2C0_Config.h 3 | * 4 | * Created on: Jul 12, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef I2C0_CONFIG_H_ 9 | #define I2C0_CONFIG_H_ 10 | 11 | 12 | void I2C0_Config(void); 13 | 14 | 15 | #endif /* I2C0_CONFIG_H_ */ 16 | -------------------------------------------------------------------------------- /Vehicle Drivers/ServiceTools.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_SERVICE_TOOLS 3 | #ifndef SERVICE_TOOLS_H 4 | #define SERVICE_TOOLS_H 5 | 6 | 7 | 8 | void ServiceTechTool(uint8_t *data); 9 | 10 | 11 | 12 | 13 | #endif // SERVICE_TOOLS_H 14 | #endif // USE_SERVICE_TOOLS 15 | -------------------------------------------------------------------------------- /Sleep.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_SLEEP 3 | #include "main.h" 4 | #include "callback.h" 5 | 6 | #ifndef SLEEP_H 7 | #define SLEEP_H 8 | 9 | void SleepCheck(uint32_t theSleepTime, Callback callback); 10 | void SleepReset(void); 11 | 12 | #endif // SLEEP_H 13 | #endif // USE_SLEEP 14 | -------------------------------------------------------------------------------- /CharArrayToInt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CharArrayToInt.h 3 | * 4 | * Created on: Aug 20, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SRC_CHARARRAYTOINT_H_ 9 | #define SRC_CHARARRAYTOINT_H_ 10 | 11 | int charArrayToInt(char *arr) ; 12 | 13 | 14 | #endif /* SRC_CHARARRAYTOINT_H_ */ 15 | -------------------------------------------------------------------------------- /TI/PWM_Config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PWM_Config.h 3 | * 4 | * Created on: Jul 23, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef PERIPHERALCONFIG_PWM_CONFIG_H_ 9 | #define PERIPHERALCONFIG_PWM_CONFIG_H_ 10 | 11 | 12 | 13 | 14 | 15 | #endif /* PERIPHERALCONFIG_PWM_CONFIG_H_ */ 16 | -------------------------------------------------------------------------------- /I2C_ISR_Callback_STM32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * I2C_ISR_Callback_STM32.h 3 | * 4 | * Created on: Aug 8, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_I2C_ISR_CALLBACK_STM32_H_ 9 | #define INC_I2C_ISR_CALLBACK_STM32_H_ 10 | 11 | 12 | 13 | #endif /* INC_I2C_ISR_CALLBACK_STM32_H_ */ 14 | -------------------------------------------------------------------------------- /ChartoByte.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ASCII_to_ByteValue.h 3 | * 4 | * Created on: Jun 11, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef ASCII_TO_BYTEVALUE_H_ 9 | #define ASCII_TO_BYTEVALUE_H_ 10 | 11 | 12 | int GetCharToByteValue(char chr); 13 | 14 | 15 | #endif /* ASCII_TO_BYTEVALUE_H_ */ 16 | -------------------------------------------------------------------------------- /TI/SystemTick_Config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SystemTick_Config.h 3 | * 4 | * Created on: Jul 12, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SYSTEMTICK_CONFIG_H_ 9 | #define SYSTEMTICK_CONFIG_H_ 10 | 11 | 12 | void SystemTick_Config(void); 13 | 14 | 15 | #endif /* SYSTEMTICK_CONFIG_H_ */ 16 | -------------------------------------------------------------------------------- /Xilinx/Peripherals_Init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Peripherals_Init.h 3 | * 4 | * Created on: May 26, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SRC_PERIPHERALS_INIT_H_ 9 | #define SRC_PERIPHERALS_INIT_H_ 10 | 11 | int Peripherals_Init(void); 12 | 13 | #endif /* SRC_PERIPHERALS_INIT_H_ */ 14 | -------------------------------------------------------------------------------- /Vehicle Drivers/NCA_From_SDAR.h: -------------------------------------------------------------------------------- 1 | #ifndef NCA_FROM_SDAR_H 2 | #define NCA_FROM_SDAR_H 3 | 4 | 5 | void SetNCA_From_SDAR_PresentFlag(bool status); 6 | bool GetNCA_From_SDAR_PresentFlag(void); 7 | void SendNCA_FROM_SDAR(uint32_t delay); 8 | 9 | void Emulate_NCA_From_SDAR(void); 10 | #endif // NCA_FROM_SDAR_H 11 | -------------------------------------------------------------------------------- /TI/SystemClock_Config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SystemClock_Config.h 3 | * 4 | * Created on: Jul 12, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SYSTEMCLOCK_CONFIG_H_ 9 | #define SYSTEMCLOCK_CONFIG_H_ 10 | 11 | 12 | void SystemClock_Config(void); 13 | 14 | 15 | #endif /* SYSTEMCLOCK_CONFIG_H_ */ 16 | -------------------------------------------------------------------------------- /Radio Drivers/RadioFunctions.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef RADIO_FUNCTIONS_H 3 | #define RADIO_FUNCTIONS_H 4 | 5 | #include "main.h" 6 | 7 | #ifndef SWC_Pin 8 | #define SWC_Pin 0 9 | #warning "SWC_Pin was not defined!" 10 | #endif // SWC_Pin 11 | 12 | void RadioCommands(uint8_t command); 13 | 14 | #endif // RADIO_FUNCTIONS_H 15 | -------------------------------------------------------------------------------- /TimerDelay.h: -------------------------------------------------------------------------------- 1 | #ifndef TIMER_DELAY_H 2 | #define TIMER_DELAY_H 3 | 4 | #include "main.h" 5 | 6 | uint32_t TimerDelayRegister(void); 7 | uint32_t TimerDelayGetValue(uint32_t timer); 8 | void TimerDelaySYSTICK(void); 9 | void TimerDelaySetValue(uint32_t timer, uint32_t value); 10 | 11 | 12 | #endif // TIMER_DELAY_H 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Don't track content of these folders 2 | MDK-ARM/Bootloader/ 3 | Drivers/ 4 | Middlewares/ 5 | 6 | 7 | # Compiled source # 8 | ################### 9 | 10 | 11 | # Packages # 12 | ############ 13 | # it's better to unpack these files and commit the raw source 14 | # git has its own built in compression methods -------------------------------------------------------------------------------- /CanBusActivity.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CanBusActivity.h 3 | * 4 | * Created on: Jan 15, 2020 5 | * Author: Karl 6 | */ 7 | 8 | #ifndef CANBUSACTIVITY_H_ 9 | #define CANBUSACTIVITY_H_ 10 | 11 | void CanBusActivityStatus(uint8_t status); 12 | uint8_t GetCanBusActivityStatus(void); 13 | 14 | #endif /* CANBUSACTIVITY_H_ */ 15 | -------------------------------------------------------------------------------- /NotifyUserDMA.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NotifyUserDMA.h 3 | * 4 | * Created on: Jan 3, 2023 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_NOTIFYUSERDMA_H_ 9 | #define INC_NOTIFYUSERDMA_H_ 10 | 11 | void NotifyUserDMA(UART_DMA_QueueStruct *msg, char *str, bool lineFeed); 12 | 13 | #endif /* INC_NOTIFYUSERDMA_H_ */ 14 | -------------------------------------------------------------------------------- /revision.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Add you revsion history here. Any text after VERSION within <> will be add to the crx file name when encrypted. Do Not Modify this line!! 4 | 5 | */ 6 | 7 | 8 | 9 | v1.0.0 10 | 11 | 12 | 13 | 14 | /* 15 | 16 | v1.0.0 start of source code 17 | 18 | 19 | 20 | 21 | 22 | 23 | */ 24 | 25 | -------------------------------------------------------------------------------- /TTP229-LSF.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_TTP229_LSF 3 | 4 | #ifndef TTP229_LSF_H 5 | #define TTP229_LSF_H 6 | 7 | #include "main.h" 8 | 9 | #define TTP229_LSF_ADDRESS 0xAE 10 | 11 | extern uint8_t i2cData[2]; 12 | 13 | HAL_I2C_StateTypeDef GetButtonsPressed(void); 14 | 15 | #endif // TTP229_LSF_H 16 | #endif // USE_TTP229_LSF 17 | -------------------------------------------------------------------------------- /Vehicle Drivers/SWC.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef SWC_H 4 | #define SWC_H 5 | 6 | void ServiceSWC(uint8_t *data); 7 | uint8_t GetSWC_ButtonStatus(void); 8 | 9 | 10 | /* 11 | function: sends command to radio. 12 | input: the SWC command 13 | output: none 14 | */ 15 | void SendSWC_Command_CAN1(uint8_t command); 16 | 17 | 18 | #endif // SWC_H 19 | -------------------------------------------------------------------------------- /FloatToString.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FloatToASCII.h 3 | * 4 | * Created on: May 21, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef FLOATTOSTRING_H_ 9 | #define FLOATTOSTRING_H_ 10 | 11 | #include "main.h" 12 | 13 | 14 | void Float_to_string(float f, uint8_t places, char strOut[]); 15 | 16 | 17 | #endif /* FLOATTOSTRING_H_ */ 18 | -------------------------------------------------------------------------------- /CommandList_Array.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CommandList_Array.h 3 | * 4 | * Created on: May 1, 2025 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_COMMANDLIST_ARRAY_H_ 9 | #define INC_COMMANDLIST_ARRAY_H_ 10 | 11 | 12 | 13 | extern int CommandList_array_size; 14 | extern int element_size; 15 | 16 | #endif /* INC_COMMANDLIST_ARRAY_H_ */ 17 | -------------------------------------------------------------------------------- /Vehicle Drivers/CAN_Activity.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CAN_Activity.h 3 | * 4 | * Created on: Jun 8, 2021 5 | * Author: codek 6 | */ 7 | 8 | #ifndef APPLICATION_USER_CORE_CAN_ACTIVITY_H_ 9 | #define APPLICATION_USER_CORE_CAN_ACTIVITY_H_ 10 | 11 | void CanBusActivityStatus(uint8_t value); 12 | 13 | #endif /* APPLICATION_USER_CORE_CAN_ACTIVITY_H_ */ 14 | -------------------------------------------------------------------------------- /Xilinx/InterruptController_Init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * InterruptController_Init.h 3 | * 4 | * Created on: Jun 4, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SRC_INTERRUPTCONTROLLER_INIT_H_ 9 | #define SRC_INTERRUPTCONTROLLER_INIT_H_ 10 | 11 | int Init_InterruptController(void); 12 | 13 | #endif /* SRC_INTERRUPTCONTROLLER_INIT_H_ */ 14 | -------------------------------------------------------------------------------- /IsHex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: IsHex.h 3 | * Author: karl.yamashita 4 | * 5 | * Created on March 14, 2023, 12:24 PM 6 | */ 7 | 8 | #ifndef ISHEX_H 9 | #define ISHEX_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | bool IsHex(char *msg, uint32_t *dataOut); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif /* ISHEX_H */ 22 | 23 | -------------------------------------------------------------------------------- /USB_Buffer.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_USB_BUFFER 3 | #ifndef USB_BUFFER_H 4 | #define USB_BUFFER_H 5 | 6 | #define USB_MAX_RING_BUFF 8 7 | 8 | int SendUsbMessage(void); 9 | void AddUsbTxBuffer(uint8_t *data); 10 | void AddUsbRxBuffer(uint8_t *data); 11 | uint8_t UsbDataAvailable(uint8_t *data); 12 | 13 | #endif // USB_BUFFER_H 14 | #endif // USE_USB_BUFFER 15 | -------------------------------------------------------------------------------- /Radio Drivers/Sony.h: -------------------------------------------------------------------------------- 1 | #ifndef SONY_H 2 | #define SONY_H 3 | 4 | 5 | 6 | // set direction of pins/ports 7 | int8_t DirectionPortB(uint16_t pin, uint8_t direction); 8 | int8_t DirectionPortC(uint16_t pin, uint8_t direction); 9 | int8_t DirectionPortD(uint16_t pin, uint8_t direction); 10 | 11 | void SonyCommand(uint8_t command); 12 | 13 | 14 | #endif // SONY_H 15 | 16 | -------------------------------------------------------------------------------- /Vehicle Drivers/CAN_Autobaud.h: -------------------------------------------------------------------------------- 1 | #ifndef CAN_AUTOBAUD_H 2 | #define CAN_AUTOBAUD_H 3 | #include "main.h" 4 | #include "stm32f1xx_hal.h" 5 | 6 | 7 | #define COUNT_BITRATE 6 8 | 9 | typedef struct Bitrate_stm { 10 | uint8_t prescaler; 11 | uint32_t BS1; 12 | uint32_t BS2; 13 | }Bitrate_stm; 14 | 15 | 16 | int8_t CAN_Autobaud(void); 17 | 18 | #endif // CAN_AUTOBAUD_H 19 | 20 | -------------------------------------------------------------------------------- /Modulo256Checksum.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Modulo256Checksum.h 3 | * 4 | * Created on: May 13, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef MODULO256CHECKSUM_H_ 9 | #define MODULO256CHECKSUM_H_ 10 | 11 | 12 | int ValidateChkSum(uint8_t *data, uint8_t len); 13 | void CalculateChkSum(uint8_t *data, uint8_t len); 14 | 15 | #endif /* MODULO256CHECKSUM_H_ */ 16 | -------------------------------------------------------------------------------- /ITOA.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ITOA.h 3 | * 4 | * Created on: May 12, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef ITOA_H_ 9 | #define ITOA_H_ 10 | 11 | enum Base_struct{ 12 | BASE_2 = 2, 13 | BASE_8 = 8, 14 | BASE_10 = 10, 15 | BASE_16 = 16 16 | }; 17 | 18 | char* itoa(int value, char* buffer, int base); 19 | 20 | #endif /* ITOA_H_ */ 21 | -------------------------------------------------------------------------------- /TCA9546A_Handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TCA9546A_Handler.h 3 | * 4 | * Created on: Jun 21, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_TCA9546A_HANDLER_H_ 9 | #define INC_TCA9546A_HANDLER_H_ 10 | 11 | int TCA9546A_GetChannel(TCA9546A_HandlerTypeDef *tca); 12 | void TCA9546A_GetChannelCallback(TCA9546A_HandlerTypeDef *tca); 13 | 14 | 15 | #endif /* INC_TCA9546A_HANDLER_H_ */ 16 | -------------------------------------------------------------------------------- /TI/ADC0_Config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ADC0_Config.h 3 | * 4 | * Created on: Jul 12, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef ADC0_CONFIG_H_ 9 | #define ADC0_CONFIG_H_ 10 | 11 | enum 12 | { 13 | ADC0_SEQ_0, 14 | ADC0_SEQ_1, 15 | ADC0_SEQ_2, 16 | ADC0_SEQ_3 17 | }ADC0_Seq; 18 | 19 | 20 | 21 | void ADC0_Config(void); 22 | 23 | 24 | #endif /* ADC0_CONFIG_H_ */ 25 | -------------------------------------------------------------------------------- /TemperatureConversion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TemperatureConversion.h 3 | * 4 | * Created on: Oct 14, 2025 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_TEMPERATURECONVERSION_H_ 9 | #define INC_TEMPERATURECONVERSION_H_ 10 | 11 | int Celsius_Fahrenheit(float *celsius, float *fahrenheit); 12 | int Fahrenheit_Celsius(float *fahrenheit, float *celsius); 13 | 14 | #endif /* INC_TEMPERATURECONVERSION_H_ */ 15 | -------------------------------------------------------------------------------- /Vehicle Drivers/ArbTextDisplayLineAttributes.h: -------------------------------------------------------------------------------- 1 | #ifndef ARB_TEXT_DISPLAY_LINE_ATTRIBUTES_H 2 | #define ARB_TEXT_DISPLAY_LINE_ATTRIBUTES_H 3 | 4 | void ServiceArbTextDisplayLineAttributes(uint8_t *data); 5 | uint8_t GetArbTextDisplayLineAttributesHead(void); 6 | uint8_t GetArbTextDisplayLineAttributesIPC(void); 7 | uint8_t GetArbTextDisplayLineAttributesRSE(void); 8 | 9 | #endif // ARB_TEXT_DISPLAY_LINE_ATTRIBUTES_H 10 | -------------------------------------------------------------------------------- /Xilinx/UartOut.h: -------------------------------------------------------------------------------- 1 | /* 2 | * UartOut.h 3 | * 4 | * Created on: Jun 2, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SRC_UARTOUT_H_ 9 | #define SRC_UARTOUT_H_ 10 | 11 | #include "main.h" 12 | 13 | 14 | HAL_StatusTypeDef UartTxMessage(UartCharBufferTxStruct *uartBufferPointer); 15 | void PrintUart1(const char8 *ptr); 16 | void PrintLine(const char8 *ptr); 17 | 18 | #endif /* SRC_UARTOUT_H_ */ 19 | -------------------------------------------------------------------------------- /UART_Handler_STM32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * UART_Handler.h 3 | * 4 | * Created on: Jul 21, 2023 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_UART_HANDLER_H_ 9 | #define INC_UART_HANDLER_H_ 10 | 11 | 12 | void UART_EnableRxInterrupt(UartBufferStruct *msg); 13 | void UART_CheckRxIntError(UartBufferStruct *msg); 14 | int UART_TxMessage_IT(UartBufferStruct *msg); 15 | 16 | 17 | #endif /* INC_UART_HANDLER_H_ */ 18 | -------------------------------------------------------------------------------- /Vehicle Drivers/Brake.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef BRAKE_H 4 | #define BRAKE_H 5 | 6 | #if defined GMLAN_V1 7 | 8 | void ServiceParkingFootBrake(unsigned char *data); 9 | unsigned char GetParkingBrakeStatus(void); 10 | unsigned char GetFootBrakeStatus(void); 11 | 12 | #endif // GMLAN_V1 13 | 14 | #if defined FORD 15 | void ServiceParkingFootBrake(unsigned char *data); 16 | 17 | #endif // FORD 18 | 19 | #endif // BRAKE_H 20 | -------------------------------------------------------------------------------- /Vehicle Drivers/DiagnosticTool.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef DIAGNOSTIC_TOOL_H 3 | #define DIAGNOSTIC_TOOL_H 4 | 5 | typedef void (*callbackDiagnosticTool)(unsigned char[8]); 6 | 7 | void ServiceDiagnosticTool(unsigned char *data); 8 | void CheckDiagnosticTool(callbackDiagnosticTool diagnosticToolCallback); 9 | void DiagnosticToolCallback(unsigned char *status); 10 | unsigned char GetDiagnosticToolStatus(void); 11 | 12 | #endif //DIAGNOSTIC_TOOL_H 13 | -------------------------------------------------------------------------------- /Linear_5_11.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Linear_5_11.h 3 | * 4 | * Created on: Nov 22, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef LINEAR_5_11_H_ 9 | #define LINEAR_5_11_H_ 10 | 11 | 12 | float L5_11_to_Float(uint16_t wordValue); 13 | uint16_t Float_to_L11(float input_val); 14 | 15 | float L16_to_Float(int exp, uint16_t input_val); 16 | uint16_t Float_to_L16(int exp, float input_val); 17 | 18 | 19 | #endif /* LINEAR_5_11_H_ */ 20 | -------------------------------------------------------------------------------- /Xilinx/SPI_ReadWrite.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPI_ReadWrite.h 3 | * 4 | * Created on: Jul 27, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SRC_SPI_READWRITE_H_ 9 | #define SRC_SPI_READWRITE_H_ 10 | 11 | int SPI_WriteData(uint8_t *SendBufPtr, uint8_t ByteCount); 12 | int SPI_TransferData(uint8_t *SendBufPtr, uint8_t *RecvBufPtr, uint8_t ByteCount); 13 | int SPI_WaitForNotBusy(void); 14 | 15 | 16 | #endif /* SRC_SPI_READWRITE_H_ */ 17 | -------------------------------------------------------------------------------- /Vehicle Drivers/TOYOTA_CAN_ID.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_TOYOTA_CAN_ID 3 | #ifndef TOYOTA_CAN_ID 4 | #define TOYOTA_CAN_ID 5 | 6 | 7 | // 2018 Tacoma? 8 | // 500kbs 9 | #define TURN_SIGNALS_ID 0x614 10 | #define LIGHTING_STATUS_ID 0x63F 11 | #define PARKING_BRAKE_DOOR_ID 0x620 12 | #define FOOT_BRAKE_ID 0x226 13 | #define GEAR_INFORMATION_ID 0x3BC 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | #endif//TOYOTA_CAN_ID 22 | #endif // USE_TOYOTA_CAN_ID 23 | -------------------------------------------------------------------------------- /Vehicle Drivers/VIN.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_VIN 3 | 4 | #ifndef VIN_H 5 | #define VIN_H 6 | 7 | 8 | #if defined GMLAN_V1 9 | 10 | void Service_VIN_2_9(unsigned char *data); 11 | void Service_VIN_10_17(unsigned char *data); 12 | 13 | 14 | int GetYear(void); 15 | bool GetHatchbackFlag(void); 16 | 17 | void GetVIN_2_9(unsigned char * data); 18 | void GetVIN_10_17(unsigned char * data); 19 | #endif // GMLAN_V1 20 | #endif // VIN_H 21 | #endif // USE_VIN 22 | -------------------------------------------------------------------------------- /I2C_Message_Handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * I2C_Bus_Reset.h 3 | * 4 | * Created on: Oct 20, 2025 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_I2C_BUS_RESET_H_ 9 | #define INC_I2C_BUS_RESET_H_ 10 | 11 | 12 | 13 | #define CMD_I2C_BUS_RESET DECLARE_CMD("i2c bus reset", 0, 0, 0, I2C_Handler, "Resets I2C bus", "i2c bus reset") 14 | 15 | 16 | int I2C_Handler(char *msg, char *retStr); 17 | 18 | int I2C_Set(char *msg, char *retStr); 19 | 20 | #endif /* INC_I2C_BUS_RESET_H_ */ 21 | -------------------------------------------------------------------------------- /DebugMode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: DebugMode.h 3 | * Author: karl.yamashita 4 | * 5 | * Created on June 1, 2023, 1:05 PM 6 | */ 7 | 8 | #ifndef DEBUGMODE_H 9 | #define DEBUGMODE_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | 16 | typedef struct 17 | { 18 | bool enable; 19 | uint8_t value; 20 | }DebugModeStructure; 21 | 22 | 23 | int DEBUG_Mode(char *msg); 24 | 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* DEBUGMODE_H */ 31 | 32 | -------------------------------------------------------------------------------- /RotaryEncoder.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_ROTARY_ENCODER 3 | #include "main.h" 4 | #include "RotaryEncoder.h" 5 | #include "tim.h" 6 | 7 | uint16_t timEncoder = 0; 8 | 9 | void RotaryEncoderCountUpdate(void) { 10 | #ifdef TIM3 11 | timEncoder = TIM3->CNT; // this timer can be any timer. For this project we are using TIM3 with encoder selected 12 | #endif // TIM3 13 | } 14 | 15 | uint16_t GetRotaryEncoderCount(void) { 16 | return timEncoder; 17 | } 18 | 19 | #endif // USE_ROTARY_ENCODER 20 | -------------------------------------------------------------------------------- /Vehicle Drivers/CAN_TransceiverMS.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_CAN_TRANSCEIVER_MS 3 | #ifndef CAN_TRANSCEIVER_MS_H 4 | #define CAN_TRANSCEIVER_MS_H 5 | 6 | #define CAN_CONTROLLER1 1 // CAN Controller number 7 | #define CAN_CONTROLLER2 2 8 | 9 | // MSCAN defines 10 | #define CAN_SLEEP 0 11 | #define CAN_NORMAL 1 12 | 13 | void CAN_TransceiverSetMode(unsigned char CAN_Controller, unsigned char mode); 14 | 15 | #endif // CAN_TRANSCEIVER_MS_H 16 | #endif // USE_CAN_BUFFER_MS 17 | -------------------------------------------------------------------------------- /Vehicle Drivers/Rap.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | 3 | 4 | #ifndef RAP_H 5 | #define RAP_H 6 | 7 | #include "main.h" 8 | #include "Sleep.h" 9 | 10 | #ifdef USE_GMLAN_DEFINES 11 | void SetRapTimerFlag(bool flag); 12 | void CheckRapStatus(uint32_t rapTimer, Callback callback); 13 | #endif // USE_GMLAN_DEFINES 14 | 15 | #if defined USE_CHRYSLER_DEFINES 16 | 17 | void ServiceRapMode(uint8_t *data); 18 | uint8_t GetRapModeFlag(void); 19 | 20 | #endif // USE_CHRYSLER_DEFINES 21 | 22 | #endif //RAP_H 23 | 24 | -------------------------------------------------------------------------------- /Xilinx/SPI_Init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SPI_Init.h 3 | * 4 | * Created on: Jul 27, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SRC_SPI_INIT_H_ 9 | #define SRC_SPI_INIT_H_ 10 | 11 | int SPI_Init(void); 12 | void SpiHandler(void *CallBackRef, u32 StatusEvent, unsigned int ByteCount); 13 | void SPI_SetTransferInProgress(bool status); 14 | bool SPI_GetTransferInProgress(void); 15 | void SPI_SetErrorCount(uint32_t count); 16 | int SPI_GetErrorCount(void); 17 | 18 | #endif /* SRC_SPI_INIT_H_ */ 19 | -------------------------------------------------------------------------------- /Vehicle Drivers/MERCEDES_CAN_ID.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_MERCEDES_CAN_ID 3 | #ifndef MERCEDES_CAN_ID 4 | #define MERCEDES_CAN_ID 5 | 6 | 7 | #define POWER_MODE_ID 0x001 8 | #define GEAR_INFORMATION_ID 0x388 9 | #define TURN_SIGNAL_HIGH_BEAMS_ID 0x45 10 | #define SWC_ID 0x3F6 11 | #define PARKING_BRAKE_ID 0x006 12 | #define PARKING_LIGHT_ID 0x04B 13 | #define DRIVER_DOOR_ID 0x002 14 | #define DIMMER_ID 0x015 15 | #define VSS_ID 0x19F 16 | 17 | #endif// MERCEDES_CAN_ID 18 | #endif // USE_MERCEDES_CAN_ID 19 | 20 | -------------------------------------------------------------------------------- /Chksum16bit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: Checksum16bit.h 3 | * Author: karl.yamashita 4 | * 5 | * Created on May 18, 2023, 11:38 AM 6 | */ 7 | 8 | #ifndef CHECKSUM16BIT_H 9 | #define CHECKSUM16BIT_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include "main.h" 16 | 17 | bool ChkSum16_Validate(uint8_t *data, uint8_t len, bool invert); 18 | void ChkSum16_Calculate(uint8_t *data, uint8_t len, bool invert); 19 | 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif /* CHECKSUM16BIT_H */ 26 | 27 | -------------------------------------------------------------------------------- /StringManip.h: -------------------------------------------------------------------------------- 1 | /* 2 | * StringManip.h 3 | * 4 | * Created on: Nov 16, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef STRINGMANIP_H_ 9 | #define STRINGMANIP_H_ 10 | 11 | void RemoveSpaces(char *str); 12 | int Get_char_Index(const char *str, char c); 13 | void Replace_Char(char *str, char findChar, char replaceChar); 14 | void ReplaceWord(char* str, char* oldWord, char* newWord); 15 | bool IsDigit(char chr); 16 | void ToLower(char *str); 17 | void ToUpper(char *str); 18 | 19 | 20 | #endif /* STRINGMANIP_H_ */ 21 | -------------------------------------------------------------------------------- /Vehicle Drivers/InfotainmentAllowed.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef INFOTAINMENT_ALLOWED_H 4 | #define INFOTAINMENT_ALLOWED_H 5 | 6 | #include 7 | #include 8 | #include "main.h" 9 | 10 | 11 | // start gateway 12 | void ServiceInfotainmentAllowed(uint8_t *data); 13 | bool GetInfotainmentAllowedStatus(void); 14 | // end gateway 15 | 16 | 17 | // start radio replacement 18 | void SendInfotainmentAllowedCallbackCAN1(int status); 19 | 20 | void SendInfotainmentAllowed(bool flag); 21 | 22 | #endif //INFOTAINMENT_ALLOWED_H 23 | -------------------------------------------------------------------------------- /SystemTick_Handler_STM32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SystemTick_Handler_STM32.h 3 | * 4 | * Created on: Oct 6, 2025 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_SYSTEMTICK_HANDLER_STM32_H_ 9 | #define INC_SYSTEMTICK_HANDLER_STM32_H_ 10 | 11 | 12 | typedef void (*SystemTickCallback)(void);// no data is passed 13 | 14 | typedef struct 15 | { 16 | SystemTickCallback callback; 17 | }SystemTick_t; 18 | 19 | void SystemTickCallbackRegister(SystemTick_t *sysTick, void *callback); 20 | 21 | #endif /* INC_SYSTEMTICK_HANDLER_STM32_H_ */ 22 | -------------------------------------------------------------------------------- /TemperatureConversion.c: -------------------------------------------------------------------------------- 1 | /* 2 | * TemperatureConversion.c 3 | * 4 | * Created on: Oct 14, 2025 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #include "main.h" 9 | 10 | 11 | int Celsius_Fahrenheit(float *celsius, float *fahrenheit) 12 | { 13 | int status = NO_ERROR; 14 | 15 | *fahrenheit = ((*celsius * 1.8) + 32); 16 | 17 | return status; 18 | } 19 | 20 | int Fahrenheit_Celsius(float *fahrenheit, float *celsius) 21 | { 22 | int status = NO_ERROR; 23 | 24 | *celsius = (*fahrenheit -32) / 1.8 ; 25 | 26 | return status; 27 | } 28 | -------------------------------------------------------------------------------- /Xilinx/GPIO_ReadWrite.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GPIO_ReadWrite.h 3 | * 4 | * Created on: Jul 27, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SRC_GPIO_READWRITE_H_ 9 | #define SRC_GPIO_READWRITE_H_ 10 | 11 | 12 | 13 | void GPIO_Read(XGpio *gpio, uint8_t channel, uint32_t *pins_OUT); 14 | void GPIO_Write(XGpio *gpio, uint8_t channel, uint32_t *pins); 15 | void GPIO_Set(XGpio *gpio, uint8_t channel, uint32_t *pins); 16 | void GPIO_Clear(XGpio *gpio, uint8_t channel, uint32_t *pins); 17 | 18 | 19 | 20 | 21 | #endif /* SRC_GPIO_READWRITE_H_ */ 22 | -------------------------------------------------------------------------------- /TTP229-LSF.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_TTP229_LSF 3 | 4 | #include "main.h" 5 | #include "TTP229-LSF.h" 6 | 7 | #include "I2C.h" 8 | 9 | /* 10 | Capacitive touch controller 11 | */ 12 | 13 | uint8_t i2cData[2]; 14 | 15 | HAL_I2C_StateTypeDef GetButtonsPressed(void) { 16 | 17 | #ifdef USING_I2C2 18 | if(HAL_I2C_Master_Receive(&hi2c2, (uint16_t)TTP229_LSF_ADDRESS, (uint8_t*)i2cData, 2, 100) != HAL_OK) { 19 | return HAL_I2C_STATE_BUSY; 20 | } 21 | #endif // USING_I2C2 22 | return HAL_I2C_STATE_READY; 23 | } 24 | 25 | 26 | #endif // USE_TTP229_LSF 27 | -------------------------------------------------------------------------------- /Vehicle Drivers/VW_CAN_ID.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_VW_CAN_ID 3 | #ifndef VW_CAN_ID 4 | #define VW_CAN_ID 5 | 6 | #define SWC_ID 0x5BF 7 | #define PARKING_BRAKE_MANUAL_ID 0x30B // manual transmission 8 | #define DOOR_PARKING_TURN_SIGNAL_ID 0x3DB 9 | #define DIMMER_ID 0x5F0 10 | #define REVERSE_ID 0x65A 11 | #define VIN_NUMBER_ID 0x6B4 12 | #define POWER_MODE 0x3C0 13 | #define PARKING_BRAKE_AUTO_ID 0x3DA // automatic transmission 14 | #define VSS_ID 0x0FD 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | #endif// VW_CAN_ID 25 | #endif // USE_VW_CAN_ID 26 | -------------------------------------------------------------------------------- /Vehicle Drivers/ClimateControlStataus.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_CLIMATE_CONTROL_STATUS 3 | #include "main.h" 4 | #include "ClimateControlStatus.h" 5 | 6 | #ifdef USING_GMLAN_V2 7 | ClimateControlStatusStruct climateControlStatusStruct; 8 | 9 | void ServiceClimateControlStatus(uint8_t *data) { 10 | climateControlStatusStruct.Bytes.byte0 = data[0] & 0x01; 11 | } 12 | 13 | uint8_t GetRearDefoggerOnStatus(void) { 14 | return climateControlStatusStruct.Status.rearWindowDefoggerOn; 15 | } 16 | #endif // USING_GMLAN_V2 17 | 18 | 19 | #endif // USE_CLIMATE_CONTROL_STATUS 20 | -------------------------------------------------------------------------------- /Vehicle Drivers/ClimateControlStatus.h: -------------------------------------------------------------------------------- 1 | #ifndef CLIMATE_CONTROL_STATUS_H 2 | #define CLIMATE_CONTROL_STATUS_H 3 | 4 | #include "main.h" 5 | 6 | #ifdef USING_GMLAN_V2 7 | 8 | typedef union ClimateControlStatusStruct { 9 | struct { 10 | uint8_t byte0; 11 | }Bytes; 12 | struct { 13 | uint8_t rearWindowDefoggerOn:1; 14 | uint8_t :7;// define later 15 | }Status; 16 | 17 | }ClimateControlStatusStruct; 18 | 19 | void ServiceClimateControlStatus(uint8_t *data); 20 | uint8_t GetRearDefoggerOnStatus(void); 21 | 22 | #endif // USING_GMLAN_V2 23 | 24 | #endif // CLIMATE_CONTROL_STATUS_H 25 | -------------------------------------------------------------------------------- /AssertParam.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AssertParam.h 3 | * 4 | * Created on: Jul 15, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef ASSERTPARAM_H_ 9 | #define ASSERTPARAM_H_ 10 | 11 | 12 | #if !defined(UNUSED) 13 | #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */ 14 | #endif /* UNUSED */ 15 | 16 | // User should use this call which will call assert_failed if not zero. 17 | #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) 18 | 19 | __weak void assert_failed(uint8_t *file, uint32_t line); 20 | 21 | 22 | #endif /* ASSERTPARAM_H_ */ 23 | -------------------------------------------------------------------------------- /Vehicle Drivers/GMLAN_CAN_ID_V2.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_GMLAN_CAN_ID_V2 3 | #ifndef GMLAN_CAN_ID_V2_H 4 | #define GMLAN_CAN_ID_V2_H 5 | 6 | 7 | #define GEAR_INFORMATION_ID 0x102CE040L // byte 0 8 | #define GEAR_INFORMATION_2_ID 0x102CC040L // byte 2 9 | #define GEAR_INFORMATION_3_ID 0x10754040L // byte 1 10 | 11 | #define POWER_MODE_ID 0x10242040L // v2 12 | 13 | #define REAR_DEFROSTER_STATUS_ID 0x10380099L // v2 14 | 15 | #define VEHICLE_SPEED_SENSE_ID 0x10210040L 16 | 17 | #define HIGH_VOLTAGE_WAKEUP_ID 0x100 18 | 19 | 20 | #endif // GMLAN_CAN_ID_V2_H 21 | #endif // USE_GMLAN_CAN_ID_V2 22 | -------------------------------------------------------------------------------- /Vehicle Drivers/ChimeStatus.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_CHIME_STATUS 3 | #include "main.h" 4 | #include "ChimeStatus.h" 5 | #include "CAN.h" 6 | #include "CAN_Buffer.h" 7 | #include "GMLAN_CAN_ID.h" 8 | 9 | CanTxMsgTypeDef canMessage; 10 | 11 | void SendChimeStatus(bool status) { 12 | memset(&canMessage, 0, sizeof(canMessage)); 13 | canMessage.ExtId = CHIME_STATUS_ID; // Set extended ID for transmit message 14 | canMessage.IDE = CAN_ID_EXT; 15 | canMessage.RTR = CAN_RTR_DATA; 16 | canMessage.DLC = 1; 17 | 18 | canMessage.Data[0] = status; 19 | AddTxBuffer1(&canMessage); 20 | } 21 | 22 | #endif // USE_CHIME_STATUS 23 | -------------------------------------------------------------------------------- /Vehicle Drivers/NCA_IntegratedRadioChassis.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_NCA_INTEGRATED_RADIO_CHASSIS 3 | #include "main.h" 4 | #include "NCA_IntegratedRadioChassis.h" 5 | #include "GMLAN_CAN_ID.h" 6 | #include "CAN.h" 7 | #include "CAN_Buffer.h" 8 | 9 | void SendNCA_IntegratedRadioChassis(void) { 10 | CanTxMsgTypeDef canMessage; 11 | canMessage.ExtId = NCA_INTEGRATED_RADIO_CHASSIS_ID; // Set extended ID for transmit message 12 | canMessage.IDE = CAN_ID_EXT; 13 | canMessage.RTR = CAN_RTR_DATA; 14 | canMessage.DLC = 0; 15 | AddMessageToCAN_Buffer2(&canMessage); 16 | } 17 | 18 | #endif// USE_NCA_INTEGRATED_RADIO_CHASSIS 19 | -------------------------------------------------------------------------------- /NotifyUser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: NotifyUser.h 3 | * Author: karl.yamashita 4 | * 5 | * Created on June 10, 2022, 12:01 PM 6 | */ 7 | 8 | #ifndef NOTIFYUSER_H 9 | #define NOTIFYUSER_H 10 | 11 | #include "UartCharBuffer.h" 12 | 13 | 14 | #ifdef __cplusplus 15 | extern "C" { 16 | #endif 17 | 18 | 19 | void NotifyUser(UartBufferStruct *msg, char *str, uint32_t strlen, bool lineFeed); 20 | void NotifyUser_Error(UartBufferStruct *msg, char *msgCpy, uint32_t error); 21 | void NotifyUser_PrintReply(UartBufferStruct *msg, char *msgCpy, char *msg2); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif /* NOTIFYUSER_H */ 28 | 29 | -------------------------------------------------------------------------------- /Radio Drivers/JVC.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef JVC_H 3 | #define JVC_H 4 | 5 | 6 | #define JVC_CUSTOM_CODE 0x8f 7 | 8 | #define JVC_VOLUME_UP 0x84 9 | #define JVC_VOLUME_DOWN 0x85 10 | #define JVC_MUTE 0x8e 11 | #define JVC_SOURCE 0x88 12 | #define JVC_TRACK_UP 0x92 13 | #define JVC_TRACK_DOWN 0x93 14 | #define JVC_BAND_DISC_UP 0x94 15 | #define JVC_PRESET_DISC_DOWN 0x95 16 | #define JVC_SELECT 0x96 17 | #define JVC_ATT 0x86 18 | #define JVC_PHONE_RECEIVE 0x98 19 | #define JVC_PHONE_REJECT 0x99 20 | #define JVC_VOICE_DIAL 0x9a 21 | #define JVC_POWER 0x80 22 | 23 | 24 | void JVC_Command(unsigned char command); 25 | 26 | 27 | #endif // JVC_H 28 | 29 | -------------------------------------------------------------------------------- /TI/Timer_Config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Timer_Config.h 3 | * 4 | * Created on: Jul 18, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef PERIPHERALCONFIG_TIMER_CONFIG_H_ 9 | #define PERIPHERALCONFIG_TIMER_CONFIG_H_ 10 | 11 | 12 | typedef struct 13 | { 14 | uint32_t timerBase; 15 | uint32_t loadCount; 16 | uint32_t config; // TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC 17 | uint32_t timerParam; // TIMER_A | TIMER_B | TIMER_BOTH 18 | uint32_t controlTrigger; // true/false 19 | }TimerConfigDef; 20 | 21 | 22 | void Timer_Config(TimerConfigDef *config); 23 | 24 | 25 | #endif /* PERIPHERALCONFIG_TIMER_CONFIG_H_ */ 26 | -------------------------------------------------------------------------------- /Xilinx/PI3USB32212.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PI3USB32212.h 3 | * 4 | * Created on: Jun 28, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_PI3USB32212_H_ 9 | #define INC_PI3USB32212_H_ 10 | 11 | 12 | typedef struct{ 13 | uint8_t function; 14 | bool newFunctionFlag; 15 | unsigned :7; 16 | }PI3USB32212_struct; 17 | 18 | enum{ 19 | SSMUX1_OE, 20 | SSMUX1_PD, 21 | SSMUX1_SEL1, 22 | SSMUX1_SEL2, 23 | 24 | SSMUX2_OE, 25 | SSMUX2_PD, 26 | SSMUX2_SEL1, 27 | SSMUX2_SEL2, 28 | }; 29 | 30 | void PI3USB32212_SetMux(uint32_t function); 31 | void PI3USB32212_SetDemux(uint32_t function); 32 | 33 | 34 | #endif /* INC_PI3USB32212_H_ */ 35 | -------------------------------------------------------------------------------- /CAN_Filter.h: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | * @attention 4 | * 5 | * Copyright (c) 2025 Karl Yamashita 6 | * All rights reserved. 7 | * 8 | * This software is licensed under terms that can be found in the LICENSE file 9 | * in the root directory of this software component. 10 | * If no LICENSE file comes with this software, it is provided AS-IS. 11 | * 12 | ****************************************************************************** 13 | */ 14 | 15 | #ifndef CAN_FILTER_H 16 | #define CAN_FILTER_H 17 | 18 | void CAN_SetFilter(CAN_MsgStruct *msg); 19 | 20 | #endif // CAN_FILTER_H 21 | 22 | -------------------------------------------------------------------------------- /INA3221_Handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * INA3221_Handler.h 3 | * 4 | * Created on: Jun 17, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_INA3221_HANDLER_H_ 9 | #define INC_INA3221_HANDLER_H_ 10 | 11 | 12 | #define USING_CALLBACK 13 | 14 | 15 | #define INA3221_SLAVE_ADDRESS_0 0x40 16 | 17 | 18 | int INA3221_SetConfigReg(I2C_GenericDef *i2c, char *msg); 19 | int INA3221_GetConfigReg(I2C_GenericDef *i2c, char *retStr); 20 | int INA3221_GetBusShunt(I2C_GenericDef *i2c, char *msg, char *retStr); 21 | 22 | void INA3221_ConfigCallback(I2C_GenericDef *i2c); 23 | void INA3221_VoltageCallback(I2C_GenericDef *i2c); 24 | 25 | #endif /* INC_INA3221_HANDLER_H_ */ 26 | -------------------------------------------------------------------------------- /Radio Drivers/Clarion.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CLARION_H 3 | #define CLARION_H 4 | 5 | #include "main.h" 6 | 7 | #define CLARION_CUSTOM_CODE 0x8660 8 | 9 | #define CLARION_VOLUME_UP 0x1b 10 | #define CLARION_VOLUME_DOWN 0x1d 11 | #define CLARION_MUTE 0x05 12 | #define CLARION_SOURCE 0x03 13 | #define CLARION_TRACK_UP 0x17 14 | #define CLARION_TRACK_DOWN 0x16 15 | #define CLARION_BAND 0x0a 16 | #define CLARION_SEND_END 0x25 17 | 18 | // custom code 2 19 | #define CLARION_CUSTOM_CODE_TRUE 1 20 | #define CLARION_CUSTOM_CODE_2 0x833b 21 | #define CLARION_SEND 0x5f 22 | #define CLARION_END 0x60 23 | 24 | void ClarionCommand(uint8_t command); 25 | 26 | 27 | #endif // CLARION_H 28 | -------------------------------------------------------------------------------- /Vehicle Drivers/TurnSignals.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_TURN_SIGNALS 3 | #ifndef TURN_SIGNALS_H 4 | #define TURN_SIGNALS_H 5 | 6 | 7 | #ifdef CHRYSLER_V3 8 | 9 | 10 | typedef union TurnSignalStatus{ 11 | struct { 12 | uint8_t byte0; 13 | }Byte; 14 | struct{ 15 | unsigned leftSignal:1; 16 | unsigned rightSignal:1; 17 | unsigned :6; 18 | }Status; 19 | }TurnSignalStatus; 20 | 21 | void ServiceTurnSignalStatus(uint8_t *data); 22 | TurnSignalStatus GetTurnSignalStatus(void); 23 | 24 | TurnSignalStatus CheckTurnSignalDoubleClickStatus(void); 25 | #endif // CHRYSLER_V3 26 | 27 | 28 | 29 | 30 | #endif // TURN_SIGNALS_H 31 | #endif // USE_TURN_SIGNALS 32 | -------------------------------------------------------------------------------- /Vehicle Drivers/VehicleSpeed.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_VEHICLE_SPEED 3 | 4 | #ifndef VEHICLE_SPEED_H 5 | #define VEHICLE_SPEED_H 6 | 7 | #include "main.h" 8 | 9 | #if defined GMLAN_V1 10 | 11 | void ServiceVehicleSpeed(uint8_t *data); 12 | uint8_t GetVehicleSpeed(void); 13 | 14 | #endif // GMLAN_V1 15 | 16 | #ifdef CHRYSLER_V5 17 | 18 | void ServiceVehicleSpeed(uint8_t *data); 19 | uint8_t GetVehicleSpeed(void); 20 | 21 | #endif // CHRYSLER_V5 22 | 23 | #ifdef CHRYSLER_V3 24 | 25 | void ServiceVehicleSpeed(uint8_t *data); 26 | uint8_t GetVehicleSpeed(void); 27 | 28 | #endif // CHRYSLER_V3 29 | 30 | #endif // VEHICLE_SPEED_H 31 | #endif // USE_VEHICLE_SPEED 32 | -------------------------------------------------------------------------------- /Radio Drivers/Alpine.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef ALPINE_H 4 | #define ALPINE_H 5 | 6 | #define ALPINE_CUSTOMCODE 0x8672 7 | 8 | #define ALPINE_VOLUME_UP 0x14 9 | #define ALPINE_VOLUME_DOWN 0x15 10 | #define ALPINE_MUTE 0x16 11 | #define ALPINE_PRESET_UP 0x0E 12 | #define ALPINE_PRESET_DOWN 0x0F 13 | #define ALPINE_SOURCE 0x0A 14 | #define ALPINE_TRACK_UP 0x12 15 | #define ALPINE_TRACK_DOWN 0x13 16 | #define ALPINE_POWER 0x09 17 | #define ALPINE_ENT_PLAY 0x07 18 | #define ALPINE_BAND_PROGRAM 0x0D 19 | #define ALPINE_RECEIVE_CALL 0x56 20 | #define ALPINE_END_CALL 0x5C 21 | #define ALPINE_VOICE 0x51 22 | 23 | 24 | void AlpineCommand(unsigned char command); 25 | 26 | #endif // ALPINE_H 27 | -------------------------------------------------------------------------------- /SigmaStudioFW.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_SIGMA_STUDIO_FW 3 | #include "main.h" 4 | #include "SigmaStudioFW.h" 5 | 6 | #include "I2C.h" 7 | 8 | 9 | 10 | void SIGMA_WRITE_REGISTER_BLOCK( devAddress, address, length, *pData ) { 11 | #ifdef USING_I2C1 12 | if(HAL_I2C_Mem_Write(&hi2c1, (uint16_t)devAddress, (uint16_t)address, (uint8_t)pData, length, 100) != HAL_OK) { 13 | return HAL_I2C_STATE_BUSY; 14 | } 15 | #endif 16 | #ifdef USING_I2C2 17 | if(HAL_I2C_Mem_Write(&hi2c2, (uint16_t)devAddress, (uint16_t)address, (uint8_t)pData, length, 100) != HAL_OK) { 18 | return HAL_I2C_STATE_BUSY; 19 | } 20 | #endif 21 | 22 | } 23 | 24 | 25 | #endif // USE_SIGMA_STUDIO_FW 26 | -------------------------------------------------------------------------------- /TI/SystemTick_Config.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SystemTick_Config.c 3 | * 4 | * Created on: Jul 12, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #include "main.h" 9 | 10 | /* 11 | * Description: Enable system tick with 1ms interrupt 12 | * 13 | * 14 | */ 15 | void SystemTick_Config(void) 16 | { 17 | // set tick period ms 18 | SysTickPeriodSet(SysCtlClockGet() / 1000); 19 | 20 | // Enable SysTick. 21 | SysTickEnable(); 22 | 23 | // Enable the SysTick Interrupt. 24 | SysTickIntEnable(); 25 | 26 | //register a handler 27 | SysTickIntRegister(SystemTick_Handler); 28 | 29 | // enable interrupt to processor 30 | IntMasterEnable(); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /CharArrayToInt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CharArrayToInt.c 3 | * 4 | * Created on: Aug 20, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #include "main.h" 9 | #include "CharArrayToInt.h" 10 | 11 | 12 | int charArrayToInt(char *arr) { 13 | int i, value, r, flag; 14 | 15 | flag = 1; 16 | i = value = 0; 17 | 18 | for( i = 0 ; i 15 | 16 | #define TCA9546A_ADDRESS (uint8_t)0b1110000 // 0x70 17 | #define TCA9546A_CHANNEL_0 0x01 18 | #define TCA9546A_CHANNEL_1 0x04 // schematic error, needs to be 0x04 19 | #define TCA9546A_CHANNEL_2 0x02 // schematic error, needs to be 0x02 20 | #define TCA9546A_CHANNELS_RESET 0 21 | 22 | i2c_error_t TCA9546A_SetChannel(uint8_t channel); 23 | i2c_error_t TCA9546A_GetSelectedChannel(uint8_t *data); 24 | 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* TCA9546A_H */ 31 | 32 | -------------------------------------------------------------------------------- /CharToByte.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ASCII_to_ByteValue.c 3 | * 4 | * Created on: Jun 11, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #include "main.h" 9 | #include "ChartoByte.h" 10 | 11 | 12 | /* 13 | * Description: Get byte value of a single character specifically for CMDx where x can equal 0-9 and A-Z 14 | * A = 10, B = 11...Y = 34, Z = 35. 15 | * 16 | * Input: ASCII character 17 | * Output: integer value of character 18 | * 19 | */ 20 | int GetCharToByteValue(char chr){ 21 | int msgPointer = 0; 22 | if(chr >= 0x30 && chr <= 0x39){ 23 | msgPointer = chr - 0x30; 24 | } 25 | else if(chr >= 0x41 && chr <= 0x5A){ 26 | msgPointer = (chr - 0x40) + 9; 27 | } 28 | else 29 | { 30 | return -1; 31 | } 32 | return msgPointer; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /ChimeGenerator.h: -------------------------------------------------------------------------------- 1 | #ifndef CHIME_GENERATOR_H 2 | #define CHIME_GENERATOR_H 3 | #include "main.h" 4 | 5 | 6 | /* 7 | These frequencies are based off TIM6 and DMA with buffer array of 256 8 | */ 9 | #define FREQ_700 400 // Prescaler=4, period=400 10 | #define FREQ_1200 225 // prescaler=4, period=225 11 | 12 | 13 | /* 14 | Decay 15 | Slow = 50 16 | medium = 25 17 | fast = 20 18 | */ 19 | #define CHIME_SPEED_SLOW 80 20 | #define CHIME_SPEED_MEDIUM 50 21 | #define CHIME_SPEED_FAST 20 22 | 23 | void ChimeInit(void); 24 | void ChimeStart(void); 25 | void ChimeStop(void); 26 | 27 | void DoChimeDecay(void); 28 | void DecayAmplitude(void); 29 | 30 | void ChimeAmplitude(uint8_t dacAmplitude); 31 | void UpdateChimeTone(uint32_t tone); 32 | void UpdateChimeSpeed(uint32_t speed); 33 | 34 | #endif // CHIME_GENERATOR_H 35 | -------------------------------------------------------------------------------- /RingBuff.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef RINGBUFF_H 4 | #define RINGBUFF_H 5 | 6 | #include "main.h" 7 | #include 8 | 9 | typedef struct { 10 | uint16_t iIndexIN; // change all these if need more than 16bits. 11 | uint16_t iIndexOUT; 12 | uint16_t iCnt_Handle; 13 | uint16_t iCnt_OverFlow; 14 | }RING_BUFF_INFO; 15 | 16 | 17 | //================================================ 18 | // FUNCTION 19 | //================================================ 20 | 21 | void DRV_RingBuffPtr__Clean(RING_BUFF_INFO *ptr); 22 | 23 | void DRV_RingBuffPtr__Input(RING_BUFF_INFO *ptr, unsigned int iBufferSize); 24 | 25 | void DRV_RingBuffPtr__Output(RING_BUFF_INFO *ptr, unsigned int iBufferSize); 26 | void DRV_RingBuffPtr__Output_JumpToNew(RING_BUFF_INFO *ptr, unsigned int iBufferSize); 27 | 28 | 29 | #endif // RINGBUFF_H 30 | -------------------------------------------------------------------------------- /UART_Handler_TM4C.h: -------------------------------------------------------------------------------- 1 | /* 2 | * UART_Handler.h 3 | * 4 | * Created on: Jul 21, 2023 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_UART_HANDLER_H_ 9 | #define INC_UART_HANDLER_H_ 10 | 11 | 12 | enum 13 | { 14 | UART_TX_DONE, 15 | UART_TX_PENDING 16 | }; 17 | 18 | 19 | void TM4C_USART_IRQHandler(UartBufferStruct *msg); 20 | 21 | int UART_TxMessage_IT(UartBufferStruct *msg); 22 | int UART_TxMessage_DMA(UartBufferStruct *msg); 23 | 24 | void SetEchoMode(bool mode); 25 | bool GetEchoMode(void); 26 | 27 | void UART_NotifyUser(UartBufferStruct *msg, char *str, uint32_t size, bool lineFeed); 28 | 29 | void TM4C_UART_Rx_IRQ(UartBufferStruct *msg); 30 | void TM4C_UART_Tx_IRQ(UartBufferStruct *msg); 31 | void TM4C_UART_ErrorCallback(UartBufferStruct *msg); 32 | 33 | 34 | #endif /* INC_UART_HANDLER_H_ */ 35 | -------------------------------------------------------------------------------- /CanBusActivity.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CanBusActivity.c 3 | * 4 | * Created on: Jan 15, 2020 5 | * Author: Karl 6 | */ 7 | #include "LSP.h" 8 | #ifdef USE_CAN_BUS_ACTIVITY_STATUS 9 | #include "main.h" 10 | #include "CanBusActivity.h" 11 | 12 | uint8_t canBusActive; 13 | 14 | /* 15 | * function: sets var to indicate CAN bus activity 16 | * input: 1 = activity 17 | * output: none 18 | */ 19 | void CanBusActivityStatus(uint8_t status){ 20 | canBusActive = status; 21 | } 22 | 23 | /* 24 | * function: check if CAN bus has activity. You can call this function to get status and then create a routine to flash an LED. 25 | * input: none 26 | * output: 1 if activity, 0 if no activity 27 | */ 28 | uint8_t GetCanBusActivityStatus(void) 29 | { 30 | if(canBusActive == 1) { 31 | canBusActive = 0; 32 | return 1; 33 | } 34 | return 0; 35 | } 36 | #endif // USE_CAN_BUS_ACTIVITY_STATUS 37 | -------------------------------------------------------------------------------- /TI/PWM_Config.c: -------------------------------------------------------------------------------- 1 | /* 2 | * PWM_Config.c 3 | * 4 | * Created on: Jul 23, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | 9 | #include "main.h" 10 | 11 | 12 | 13 | void PWM_Config(void) 14 | { 15 | MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); 16 | while(!SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0)); 17 | 18 | MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); 19 | 20 | MAP_GPIOPinConfigure(GPIO_PE5_M0PWM5); 21 | MAP_GPIOPinTypePWM(GPIO_PORTB_BASE, FAN_PWM_Pin); 22 | 23 | // 24 | // Set the PWM period to 25kHz. To calculate the appropriate parameter 25 | // use the following equation: N = (1 / f) * SysClk. Where N is the 26 | // function parameter, f is the desired frequency, and SysClk is the 27 | // system clock frequency. 28 | // 29 | MAP_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, (SysCtlClockGet() / 25000)); 30 | 31 | } 32 | 33 | -------------------------------------------------------------------------------- /TI/UART_Config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * UART_Config.h 3 | * 4 | * Created on: Jul 17, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef PERIPHERALCONFIG_UART_CONFIG_H_ 9 | #define PERIPHERALCONFIG_UART_CONFIG_H_ 10 | 11 | 12 | typedef struct 13 | { 14 | uint32_t uart_base; // UART0_BASE 15 | uint32_t sys_ctl_peripheral; // SYSCTL_PERIPH_UART0 16 | uint32_t systemClock; 17 | uint32_t baudRate; // 115200 18 | uint32_t GPIOPinConfigureRx; // GPIO_PA0_U0RX 19 | uint32_t GPIOPinConfigureTx; // GPIO_PA1_U0TX 20 | uint32_t GPIOPinType; // UART0_RX_Pin | UART0_TX_Pin 21 | uint32_t GPIOPinTypeBase; // GPIO_PORTA_BASE 22 | uint32_t IntEnable; // INT_UART0 23 | void (*UartIntRegister)(void); // USART0_IRQHandler 24 | }UART_ConfigDef; 25 | 26 | 27 | void USART_Config(UART_ConfigDef *config); 28 | 29 | 30 | #endif /* PERIPHERALCONFIG_UART_CONFIG_H_ */ 31 | -------------------------------------------------------------------------------- /UART_Handler_dsPIC33.h: -------------------------------------------------------------------------------- 1 | /* 2 | * UART_Handler.h 3 | * 4 | * Created on: Jul 21, 2023 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_UART_HANDLER_H_ 9 | #define INC_UART_HANDLER_H_ 10 | 11 | 12 | // PORT number defines to assign to instance. 13 | enum 14 | { 15 | UART_PORT_0, 16 | UART_PORT_1, 17 | UART_PORT_2, 18 | UART_PORT_3, 19 | UART_PORT_4, 20 | UART_PORT_5, 21 | UART_PORT_6, 22 | UART_PORT_7, 23 | UART_PORT_8, 24 | UART_PORT_9, 25 | UART_PORT_10, 26 | UART_PORT_11, 27 | UART_PORT_12, 28 | UART_PORT_13, 29 | UART_PORT_14, 30 | UART_PORT_15 31 | // add more if needed. 32 | }; 33 | 34 | void UART1_Receive_CallBack(void); 35 | void UART2_Receive_CallBack(void); 36 | void UART_TX_AddDataToBuffer(UartBufferStruct *msgOut, uint8_t *msgIN, uint32_t dataSize); 37 | int UART_TxMessage(UartBufferStruct *msg); 38 | 39 | 40 | #endif /* INC_UART_HANDLER_H_ */ 41 | -------------------------------------------------------------------------------- /Vehicle Drivers/CAN_TransceiverFD.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_CAN_TRANSCEIVER_FD 3 | #ifndef CAN_TRANSCEIVER_FD_H 4 | #define CAN_TRANSCEIVER_FD_H 5 | 6 | #include "can.h" 7 | 8 | 9 | #define CAN_CONTROLLER1 1 // CAN Controller number 10 | #define CAN_CONTROLLER2 2 11 | 12 | // MSCAN defines 13 | #define CAN_SLEEP 0 14 | #define CAN_NORMAL 1 15 | 16 | #ifdef USE_CAN_BUFFER_1 17 | void InitCAN_Transceiver(void); 18 | void CAN_TransceiverSleep(void); 19 | void CAN_TransceiverSetMode(unsigned char CAN_Controller, unsigned char mode); 20 | #endif // USE_1_BUFFERS 21 | #ifdef USE_CAN_BUFFER_2 22 | void InitDualCanTransceiver(void); 23 | void DualCanTransceiverSleep(void); 24 | void CAN_DualTransceiverSetMode(unsigned char CAN_Controller, unsigned char mode); 25 | #endif // USE_2_BUFFERS 26 | 27 | 28 | #endif // CAN_TRANSCEIVER_FD_H 29 | #endif // USE_CAN_TRANSCEIVER_FD 30 | -------------------------------------------------------------------------------- /AssertParam.c: -------------------------------------------------------------------------------- 1 | /* 2 | * AssertParam.c 3 | * 4 | * Created on: Jul 15, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | 9 | #include "main.h" 10 | 11 | 12 | /* 13 | * Description: A better approach to using assert where user can do some debugging in assert_failed() function. 14 | * TI's assert is a macro so can't override. 15 | * 16 | */ 17 | 18 | 19 | // User should override this function. 20 | __weak void assert_failed(uint8_t *file, uint32_t line) 21 | { 22 | // do not modify this function. Override it instead. 23 | UNUSED(file); 24 | UNUSED(line); 25 | } 26 | 27 | 28 | 29 | /* 30 | * Example how to use. 31 | * 32 | * #define IS_UART_BASE(__UARTBASE__) ( ((__UARTBASE__) == UART0_BASE) || ((__UARTBASE__) == UART1_BASE) ) 33 | * 34 | * assert_param(IS_UART_BASE(UART0_BASE)); // if not zero, will call assert_failed() with parameters. 35 | * 36 | */ 37 | -------------------------------------------------------------------------------- /Vehicle Drivers/AudioSourceStatus.h: -------------------------------------------------------------------------------- 1 | #ifdef USE_AUDIO_SOURCE_STATUS 2 | #ifndef AUDIO_SOURCE_STATUS_H 3 | #define AUDIO_SOURCE_STATUS_H 4 | 5 | #include "main.h" 6 | #include "GMLAN_Defines.h" 7 | #include "can.h" 8 | 9 | 10 | typedef union AudioSourceStatus 11 | { 12 | struct{ 13 | unsigned char byte1; 14 | unsigned char byte0; 15 | }Bytes; 16 | struct{ 17 | unsigned statusCode:4; 18 | unsigned channelType:3; 19 | unsigned sourceType:5; 20 | unsigned :4; 21 | }Status; 22 | }AudioSourceStatus; 23 | 24 | void ServiceAudioSourceStatusXM(unsigned char *data); 25 | 26 | void ServiceAudioSourceStatusOnStar(unsigned char *data); 27 | 28 | void SendAudioSourceStatusSoh(uint8_t sourceType, uint32_t sohTimer); 29 | 30 | void SendAudioSourceStatusCAN1(uint32_t canID, AudioSourceStatus *audioSourceStatus); 31 | 32 | #endif // AUDIO_SOURCE_STATUS_H 33 | 34 | #endif // USE_AUDIO_SOURCE_STATUS 35 | -------------------------------------------------------------------------------- /Vehicle Drivers/GearInformation.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef GEAR_INFORMATION_H 3 | #define GEAR_INFORMATION_H 4 | 5 | #if defined GMLAN_V1 6 | 7 | #define BETWEEN_RANGES 0 8 | #define PARK_RANGE 1 9 | #define REVERSE_RANGE 2 10 | #define NUETRAL_RANGE 3 11 | #define FORWARD_RANGE_A 4 12 | 13 | #endif // GMLAN_V1 14 | 15 | #if defined USING_GMLAN_V2 16 | 17 | // TODO - need to verify these values 18 | #define BETWEEN_RANGES 0 19 | #define PARK_RANGE 0x0F 20 | #define REVERSE_RANGE 0x0E 21 | #define NUETRAL_RANGE 0x0D 22 | #define DRIVE_RANGE 0x01 23 | 24 | #endif // USING_GMLAN_V2 25 | 26 | #if defined CHRYSLER_V3 27 | 28 | #define PARK_RANGE 0x0D 29 | #define REVERSE_RANGE 0x0B 30 | #define NUETRAL_RANGE 0x00 31 | #define DRIVE_RANGE 0x01 32 | 33 | #endif // CHYSLER_V3 34 | 35 | void ServiceGearInformation(uint8_t *data); 36 | uint8_t GetGearInformation(void); 37 | 38 | 39 | #endif // GEAR_INFORMATION_H 40 | -------------------------------------------------------------------------------- /Vehicle Drivers/AudioMasterCommand.h: -------------------------------------------------------------------------------- 1 | #ifdef USE_AUDIO_MASTER_COMMAND 2 | #ifndef AUDIO_MASTER_ARBITRATION_COMMAND_H 3 | #define AUDIO_MASTER_ARBITRATION_COMMAND_H 4 | 5 | #include 6 | #include "can.h" 7 | #include "main.h" 8 | 9 | typedef union AudioMasterArbCommand{ 10 | struct{ 11 | unsigned char byte1; 12 | unsigned char byte0; 13 | }Bytes; 14 | struct{ 15 | unsigned sourceType:5; 16 | unsigned :3; 17 | unsigned channelType:3; 18 | unsigned command:4; 19 | unsigned :1; 20 | }Status; 21 | }AudioMasterArbitrationCommand; 22 | 23 | void SendAudioMasterArbitrationCommandSoh(uint32_t sohTimer); 24 | void SendAudioMasterArbitrationCommandCAN2(AudioMasterArbitrationCommand *audioMasterArbitrationCommand); 25 | 26 | bool ServiceAudioMasterArbitrationCommandAsGateway(uint8_t *data); 27 | 28 | 29 | #endif // AUDIO_MASTER_ARBITRATION_COMMAND_H 30 | 31 | #endif // USE_AUDIO_MASTER_COMMAND 32 | 33 | -------------------------------------------------------------------------------- /Vehicle Drivers/CAN_TransceiverLSFT.h: -------------------------------------------------------------------------------- 1 | #ifndef CAN_TRANSCEIVER_LSFT_H 2 | #define CAN_TRANSCEIVER_LSFT_H 3 | 4 | #if defined hcan1 || defined hcan2 5 | #include "can.h" 6 | #endif // hcan1 7 | #define CAN_CONTROLLER1 1 // CAN Controller number 8 | #define CAN_CONTROLLER2 2 9 | 10 | // LSFT defines 11 | #define CAN_SLEEP 0 12 | #define CAN_NORMAL 1 13 | #define CAN_POWER_ON_STANDBY 2 14 | #define CAN_GOTO_SLEEP 3 15 | 16 | #if defined USE_1_BUFFER 17 | void InitCAN_Transceiver(void); 18 | void CAN_TransceiverSleep(void); 19 | void CAN_TransceiverSetMode(unsigned char CAN_Controller, unsigned char mode); 20 | #endif // USE_1_BUFFERS 21 | #if defined USE_2_BUFFERS 22 | void InitDualCanTransceiver(void); 23 | void DualCanTransceiverSleep(void); 24 | void CAN_DualTransceiverSetMode(unsigned char CAN_Controller, unsigned char mode); 25 | #endif // USE_2_BUFFERS 26 | 27 | 28 | 29 | #endif // CAN_TRANSCEIVER_LSFT_H 30 | -------------------------------------------------------------------------------- /ascii_to_hex.c: -------------------------------------------------------------------------------- 1 | 2 | #include "main.h" 3 | #include "ascii_to_hex.h" 4 | 5 | const uint8_t hex[] = {0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa,0xb,0xc,0xd,0xe,0xf}; 6 | int AscII2hex(char input, uint8_t *output) 7 | { 8 | int status = 0; 9 | switch (input-48){ 10 | // input is "0-9" in ascii 11 | case 0: case 1: case 2: case 3: case 4: 12 | case 5: case 6: case 7: case 8: case 9: 13 | *output = hex[input-48]; 14 | break; 15 | // input is "A-F" in ascii 16 | case 17: case 18: case 19: 17 | case 20: case 21: case 22: 18 | *output = hex[input-55]; 19 | break; 20 | // input is "a-f" in ascii 21 | case 49: case 50: case 51: 22 | case 52: case 53: case 54: 23 | *output = hex[input-87]; 24 | break; 25 | // mask error bits onto the return 26 | default: 27 | status = -1; 28 | break; 29 | } 30 | // error return type 31 | return status; 32 | } 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /HC4052_Control.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_HC4052_CONTROL 3 | #include "main.h" 4 | #include "HC4052_Control.h" 5 | #include "gpio.h" 6 | #include "GPIO_Ports.h" 7 | 8 | /* 9 | 10 | 74HCT4052 Dual 4-channel Analog multiplexer 11 | */ 12 | 13 | #if defined C3_M40_BOARD 14 | 15 | void SetAnalogOutput(uint8_t analogOuput) { 16 | switch(analogOuput) { 17 | case 0: // rear 18 | PortC_Off(HC4052_S0_Pin); 19 | PortC_Off(HC4052_S1_Pin); 20 | break; 21 | case 1: // Front 22 | PortC_On(HC4052_S0_Pin); 23 | PortC_Off(HC4052_S1_Pin); 24 | break; 25 | case 2: // Left 26 | PortC_Off(HC4052_S0_Pin); 27 | PortC_On(HC4052_S1_Pin); 28 | break; 29 | case 3: // Right 30 | PortC_On(HC4052_S0_Pin); 31 | PortC_On(HC4052_S1_Pin); 32 | break; 33 | default: 34 | PortC_Off(HC4052_S0_Pin); 35 | PortC_Off(HC4052_S1_Pin); 36 | break; 37 | } 38 | } 39 | 40 | #endif // C3_M40_BOARD 41 | #endif // USE_HC4052_CONTROL 42 | 43 | -------------------------------------------------------------------------------- /Vehicle Drivers/Brake.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_BRAKE 3 | #include "main.h" 4 | #include "Brake.h" 5 | 6 | #if defined GMLAN_V1 7 | 8 | #define BRAKE_DATA_LENGTH 4 9 | 10 | unsigned char brakeArray[BRAKE_DATA_LENGTH]; 11 | unsigned char footBrakeStatus; 12 | unsigned char parkingBrakeStatus; 13 | 14 | void ServiceParkingFootBrake(unsigned char *data){ 15 | unsigned char i; 16 | for (i = 0; i < BRAKE_DATA_LENGTH; i++) { 17 | brakeArray[i] = data[i]; 18 | } 19 | } 20 | 21 | unsigned char GetParkingBrakeStatus(void){ 22 | if ((brakeArray[1] & 0x02) == 0x02) { 23 | parkingBrakeStatus = 1; 24 | } else { 25 | parkingBrakeStatus = 0; 26 | } 27 | return parkingBrakeStatus; 28 | } 29 | 30 | unsigned char GetFootBrakeStatus(void) { 31 | if ((brakeArray[1] & 0x80) == 0x80) { 32 | footBrakeStatus = 1; 33 | } else { 34 | footBrakeStatus = 0; 35 | } 36 | return footBrakeStatus; 37 | } 38 | 39 | 40 | #endif // GMLAN_V1 41 | #endif // USE_BRAKE 42 | -------------------------------------------------------------------------------- /FSAV331_Control.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_FSAV331_CONTROL 3 | #include "main.h" 4 | #include "FSAV331_Control.h" 5 | #include "gpio.h" 6 | #include "GPIO_Ports.h" 7 | 8 | 9 | /* 10 | Dual Video switch 11 | */ 12 | 13 | 14 | #if defined C3_M40_BOARD 15 | 16 | 17 | // todo need to see if OE1 or OE2 pins need to be enabled 18 | void SetVideoOutput(uint8_t videoOuput) { 19 | switch(videoOuput) { 20 | case 0: // rear 21 | PortC_Off(FSAV_S0_Pin); 22 | PortC_Off(FSAV_S1_Pin); 23 | break; 24 | case 1: // Front 25 | PortC_On(FSAV_S0_Pin); 26 | PortC_Off(FSAV_S1_Pin); 27 | break; 28 | case 2: // Left 29 | PortC_Off(FSAV_S0_Pin); 30 | PortC_On(FSAV_S1_Pin); 31 | break; 32 | case 3: // Right 33 | PortC_On(FSAV_S0_Pin); 34 | PortC_On(FSAV_S1_Pin); 35 | break; 36 | default: 37 | PortC_Off(FSAV_S0_Pin); 38 | PortC_Off(FSAV_S1_Pin); 39 | break; 40 | } 41 | } 42 | 43 | #endif // C3_M40_BOARD 44 | #endif // USE_FSAV331_CONTROL 45 | 46 | -------------------------------------------------------------------------------- /TCA9546A_Handler.c: -------------------------------------------------------------------------------- 1 | /* 2 | * TCA9546A_Handler.c 3 | * 4 | * Created on: Jun 21, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | 9 | #include "main.h" 10 | 11 | 12 | extern UART_DMA_QueueStruct uart2; 13 | 14 | TCA9546A_HandlerTypeDef tca = {0}; 15 | 16 | 17 | 18 | int TCA9546A_GetChannel(TCA9546A_HandlerTypeDef *tca) 19 | { 20 | int status = NO_ERROR; 21 | 22 | status = TCA9546A_Read(tca, TCA9546A_GetChannelCallback); 23 | if(status != NO_ERROR) 24 | { 25 | return status; 26 | } 27 | else 28 | { 29 | return NO_ACK; // callback will return channel 30 | } 31 | 32 | return status; 33 | } 34 | 35 | 36 | 37 | // CALLBACKS 38 | 39 | 40 | void TCA9546A_GetChannelCallback(TCA9546A_HandlerTypeDef *tca) 41 | { 42 | uint32_t channel = 0; 43 | char str[128] = {0}; 44 | 45 | channel = tca->i2c_Instance->dataPtr[0]; 46 | 47 | sprintf(str, "%s=%ld", tca->commandCopy, channel); 48 | 49 | UART_DMA_NotifyUser(&uart2, str, strlen(str), true); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /TI/I2C0_Config.c: -------------------------------------------------------------------------------- 1 | /* 2 | * I2C0_Config.c 3 | * 4 | * Created on: Jul 12, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | 9 | #include "main.h" 10 | 11 | 12 | I2C_GenericDef i2c0 = 13 | { 14 | .i2c_base = I2C0_BASE 15 | }; 16 | 17 | 18 | /* 19 | * Description: Master for MCDP6200, INA3221 and TMP108 sensors 20 | * 21 | * 22 | * 23 | */ 24 | void I2C0_Config(void) 25 | { 26 | SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); 27 | while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C0)) 28 | { 29 | } 30 | SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); 31 | while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB)) 32 | { 33 | } 34 | 35 | GPIOPinConfigure(GPIO_PB2_I2C0SCL); 36 | GPIOPinConfigure(GPIO_PB3_I2C0SDA); 37 | 38 | GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2); 39 | GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3); 40 | 41 | // init the master module clock and 100kbps 42 | I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false); 43 | } 44 | -------------------------------------------------------------------------------- /Vehicle Drivers/AdvancedRemoteReceiverControl.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef ADVANCED_REMOTE_RECEIVER_CONTROL_H 3 | #define ADVANCED_REMOTE_RECEIVER_CONTROL_H 4 | 5 | typedef union AdvancedRemoteReceiverControl{ 6 | struct { 7 | uint8_t byte3; 8 | uint8_t byte2; 9 | uint8_t byte1; 10 | uint8_t byte0; 11 | }Bytes; 12 | struct { 13 | unsigned remoteRecieverTuneValue:16; 14 | 15 | unsigned informationRequest:1; 16 | unsigned :2; 17 | unsigned remoteReceiverTuneCommand:5; 18 | 19 | unsigned :1; 20 | unsigned groupCommand:3; 21 | unsigned headUnitRemoteReceiverControllerTargetDevice:4; 22 | }AdvancedRemoteReceiverControlBits; 23 | }AdvancedRemoteReceiverControl; 24 | 25 | 26 | void ServiceAdvancedRemoteReceiverControl(uint8_t *data); 27 | bool ServiceAdvancedRemoteReceiverControlAsGateway(uint8_t *data); 28 | 29 | void SendAdvancedRemoteReceiverControlCAN2(AdvancedRemoteReceiverControl *advancedRemoteReceiverControl); 30 | 31 | 32 | #endif // ADVANCED_REMOTE_RECEIVER_CONTROL_H 33 | -------------------------------------------------------------------------------- /Vehicle Drivers/MirrorMovementRequest.h: -------------------------------------------------------------------------------- 1 | #ifndef MIRROR_MOVEMENT_REQUEST_H 2 | #define MIRROR_MOVEMENT_REQUEST_H 3 | 4 | 5 | typedef union MirrorMovementRequest { 6 | struct { 7 | uint8_t byte1; 8 | uint8_t byte0; 9 | }ByteArray; 10 | struct { 11 | unsigned MirrorFoldRequest:2; 12 | unsigned MirrorExtensionRequest:2; 13 | unsigned PassengerMirrorParkingTiltRequest:2; 14 | unsigned :2; 15 | unsigned MirrorSwitchActivationLeftRight:2; 16 | unsigned MirrorSwitchActivationUpDown:2; 17 | unsigned MirrorSelectSwitchStatus:2; 18 | unsigned :2; 19 | }Status; 20 | }MirrorMovementRequest; 21 | 22 | typedef struct { 23 | bool mirrorUpActive; 24 | bool mirrorDownActive; 25 | bool mirrorLeftActive; 26 | bool mirrorRightActive; 27 | unsigned :4; 28 | }MirrorStatus; 29 | 30 | void ServiceMirrorMovementRequest(uint8_t *data); 31 | void CheckMirrorMovementRequest(uint32_t delay); 32 | MirrorStatus GetMirrorStatusActiveFlag(void); 33 | 34 | #endif // MIRROR_MOVEMENT_REQUEST_H 35 | -------------------------------------------------------------------------------- /MCDP6200_I2C_ReadWrite.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: MCDP6200.h 3 | * Author: karl.yamashita 4 | * 5 | * Created on January 14, 2021, 1:12 PM 6 | */ 7 | 8 | #ifndef MCDP6200_H 9 | #define MCDP6200_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | 16 | #define MCDP6200_I2C_PORT I2C_PORT_1 17 | #define REG_SIZE 2 // register is 2 bytes 18 | 19 | enum{ 20 | READ, 21 | WRITE 22 | }; 23 | 24 | // end structures 25 | 26 | typedef enum { 27 | I2C_NOERR, // The message was sent. 28 | I2C_FAIL, // Message was NOT sent, bus failure 29 | I2C_BUSY // Message was NOT sent, bus was busy. 30 | // If you are interested in the failure reason, 31 | // Sit on the event call-backs. 32 | } i2c_error_t; 33 | 34 | // prototypes 35 | 36 | int MCDP6200_Write_Register(uint8_t devAddr, uint32_t _register, uint8_t *data); 37 | int MCDP6200_Read_Register_Data(uint8_t devAddr, uint32_t _register, uint8_t *data); 38 | 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif /* MCDP6200_H */ 45 | 46 | -------------------------------------------------------------------------------- /Vehicle Drivers/GearInformation.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_GEAR_INFORMATION 3 | #include "main.h" 4 | #include "GearInformation.h" 5 | 6 | #ifdef USING_GMLAN_V1 7 | 8 | uint8_t gearInformation; 9 | 10 | void ServiceGearInformation(uint8_t *data) { 11 | gearInformation = (data[1] >> 4 ) & 0x0F; 12 | } 13 | 14 | uint8_t GetGearInformation(void) { 15 | return gearInformation; 16 | } 17 | #endif // USING_GMLAN_V1 18 | 19 | #ifdef USING_GMLAN_V2 20 | 21 | uint8_t gearInformation; 22 | 23 | void ServiceGearInformation(uint8_t *data) { 24 | gearInformation = (data[0]) & 0xF0; // low nibble 25 | } 26 | 27 | uint8_t GetGearInformation(void) { 28 | return gearInformation; 29 | } 30 | 31 | #endif // USING_GMLAN_V2 32 | 33 | #ifdef CHRYSLER_V3 34 | 35 | uint8_t gearInformation; 36 | 37 | void ServiceGearInformation(uint8_t *data) { 38 | gearInformation = data[2] & 0x0F; 39 | } 40 | 41 | uint8_t GetGearInformation(void) { 42 | return gearInformation; 43 | } 44 | 45 | #endif // CHRYSLER_V3 46 | #endif // USE_GEAR_INFORMATION 47 | -------------------------------------------------------------------------------- /NotifyUserDMA.c: -------------------------------------------------------------------------------- 1 | /* 2 | * NotifyUserDMA.c 3 | * 4 | * Created on: Jan 3, 2023 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #include "main.h" 9 | 10 | /* 11 | * Description: This will add CR and LF to string before saving to tx buffer. 12 | * Input: Pointer to buffer, the string to add to tx buffer, and linefeed enable 13 | * 14 | */ 15 | void NotifyUserDMA(UART_DMA_QueueStruct *msg, char *str, bool lineFeed) 16 | { 17 | uint8_t strMsg[UART_DMA_DATA_SIZE] = {0}; 18 | uint8_t *ptr = strMsg; 19 | int i = 0; 20 | 21 | strcpy((char*)strMsg, str); 22 | 23 | if(lineFeed == true) 24 | { 25 | strcat((char*)strMsg, "\r\n"); 26 | } 27 | 28 | memset(&msg->tx.queue[msg->tx.ptr.index_IN].data, 0 , sizeof(msg->tx.queue[msg->tx.ptr.index_IN].data)); 29 | 30 | msg->tx.queue[msg->tx.ptr.index_IN].size = strlen((char*)strMsg); 31 | while(*ptr != '\0') 32 | { 33 | msg->tx.queue[msg->tx.ptr.index_IN].data[i++] = *ptr++; 34 | } 35 | 36 | RingBuff_Ptr_Input(&msg->tx.ptr, UART_DMA_QUEUE_SIZE); 37 | } 38 | -------------------------------------------------------------------------------- /Vehicle Drivers/CAN_Handler.c: -------------------------------------------------------------------------------- 1 | /* 2 | * CAN_Handler.c 3 | * 4 | * Created on: Jan 7, 2023 5 | * Author: codek 6 | */ 7 | 8 | 9 | #include "main.h" 10 | #include "CAN_Handler.h" 11 | 12 | 13 | extern CAN_HandleTypeDef hcan; 14 | extern CanMsg_Struct CAN_Msg; 15 | 16 | 17 | /* 18 | Description: Callback when message is pending. Get message by passing buffer address. Then increment buffer pointer. 19 | input: CAN instance 20 | output: none 21 | */ 22 | 23 | void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *_hcan) 24 | { 25 | CanRx *ptr; 26 | 27 | if(_hcan == &hcan) 28 | { 29 | ptr = &CAN_Msg.rx.queue[CAN_Msg.rx.ptr.index_IN]; 30 | CAN_Msg.canBusActive = 1; // indicate msg received 31 | HAL_CAN_GetRxMessage(_hcan, (uint32_t) CAN_RX_FIFO0, &ptr->header, ptr->data); 32 | RingBuff_Ptr_Input(&CAN_Msg.rx.ptr, CAN_Msg.rx.msgQueueSize); 33 | } 34 | } 35 | 36 | 37 | // We should never need this callback as the CAN buffer should take care of messages received. 38 | // void HAL_CAN_RxFifo0FullCallback(CAN_HandleTypeDef *hcan) 39 | 40 | -------------------------------------------------------------------------------- /I2C_Message_Handler.c: -------------------------------------------------------------------------------- 1 | /* 2 | * I2C_Bus_Reset.c 3 | * 4 | * Created on: Oct 20, 2025 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #include "main.h" 9 | 10 | int I2C_Handler(char *msg, char *retStr) 11 | { 12 | int status = NO_ERROR; 13 | char *result; 14 | char getChar[] = "?"; // the char that indicates a get command 15 | 16 | RemoveSpaces(msg); 17 | 18 | // check if get command (?) 19 | result = strstr(msg, getChar); 20 | if(result) 21 | { 22 | return WRITE_ONLY_ERROR; 23 | } 24 | // no ?, so is a set command 25 | status = I2C_Set(msg, retStr); //set 26 | 27 | return status; 28 | } 29 | 30 | int I2C_Set(char *msg, char *retStr) 31 | { 32 | int status = NO_ERROR; 33 | char *token; // command 34 | char *rest = msg; 35 | char delim[] = "?:,\r"; 36 | 37 | token = strtok_r(rest, delim, &rest); // command 38 | 39 | if(strncmp(token, "busreset", strlen("busreset")) == 0) 40 | { 41 | HAL_I2C_DeInit(&hi2c2); 42 | 43 | HAL_I2C_Init(&hi2c2); 44 | } 45 | else 46 | { 47 | status = COMMAND_UNKNOWN; 48 | } 49 | 50 | return status; 51 | } 52 | -------------------------------------------------------------------------------- /TI/IRQ_Handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * irqHandler.h 3 | * 4 | * Created on: Mar 5, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef IRQ_HANDLER_H_ 9 | #define IRQ_HANDLER_H_ 10 | 11 | 12 | #define ADC0_FIFO_SIZE 8 13 | #define ADC1_FIFO_SIZE 4 14 | 15 | #define HAL_MAX_DELAY 0xFFFFFFFFU 16 | 17 | typedef enum 18 | { 19 | HAL_TICK_FREQ_10HZ = 100U, 20 | HAL_TICK_FREQ_100HZ = 10U, 21 | HAL_TICK_FREQ_1KHZ = 1U, 22 | HAL_TICK_FREQ_DEFAULT = HAL_TICK_FREQ_1KHZ 23 | } HAL_TickFreqTypeDef; 24 | 25 | 26 | void SysTick_Handler(void); 27 | void HAL_IncTick(void); 28 | uint32_t HAL_GetTick(void); 29 | void HAL_Delay(uint32_t Delay); 30 | 31 | void ADC0_IRQHandler(void); 32 | void ADC1_IRQHandler(void); 33 | void I2C0_EV_IRQHandler(void); 34 | void I2C1_EV_IRQHandler(void); 35 | void PortAIntHandler(void); 36 | void PortBIntHandler(void); 37 | void USART0_IRQHandler(void); 38 | void USART3_IRQHandler(void); 39 | 40 | uint32_t GetADC0_Value(uint8_t ptr); 41 | uint32_t GetADC1_Value(uint8_t ptr); 42 | 43 | #endif /* IRQ_HANDLER_H_ */ 44 | -------------------------------------------------------------------------------- /STM32_UID.h: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | * @attention 4 | * 5 | * Copyright (c) 2025 Karl Yamashita 6 | * All rights reserved. 7 | * 8 | * This software is licensed under terms that can be found in the LICENSE file 9 | * in the root directory of this software component. 10 | * If no LICENSE file comes with this software, it is provided AS-IS. 11 | * 12 | ****************************************************************************** 13 | */ 14 | 15 | /* 16 | * STM32_UID.h 17 | * 18 | * Created on: Sep 3, 2025 19 | * Author: codek 20 | */ 21 | 22 | #ifndef INC_STM32_UID_H_ 23 | #define INC_STM32_UID_H_ 24 | 25 | #define STM32_UID_DATA_SIZE 12 26 | 27 | typedef union 28 | { 29 | struct 30 | { 31 | uint64_t low; 32 | uint32_t high; 33 | }; 34 | struct 35 | { 36 | uint32_t uid_0; 37 | uint32_t uid_1; 38 | uint32_t uid_2; 39 | }UID_t; 40 | }STM32_UID_t; 41 | 42 | int STM32_UID_Get(char *retStr); 43 | void STM32_UID(STM32_UID_t *msg); 44 | 45 | #endif /* INC_STM32_UID_H_ */ 46 | -------------------------------------------------------------------------------- /Xilinx/I2C_ReadWrite.h: -------------------------------------------------------------------------------- 1 | /* 2 | * I2C_ReadWrite.h 3 | * 4 | * Created on: Jul 1, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SRC_I2C_READWRITE_H_ 9 | #define SRC_I2C_READWRITE_H_ 10 | 11 | #define I2C_TIMEOUT 100 12 | 13 | #define I2C_PORT_0 0 14 | #define I2C_PORT_1 1 15 | #define I2C_PORT_2 2 16 | 17 | int I2C_Send_Data(uint8_t i2c_port, uint8_t devAddr, uint8_t *TxMsgPtr, int ByteCount, uint8_t option); 18 | int I2C_Get_Data(uint8_t i2c_port, uint8_t devAddr, uint8_t *RxMsgPtr, int ByteCount, uint8_t option); 19 | int I2C_Get_Register_Data(uint8_t i2c_port, uint8_t devAddr, uint8_t regAddr, uint8_t *RxMsgPtr, int ByteCount); 20 | 21 | /* 22 | * These below don't work. XIic_MasterSend & XIic_MasterRecv don't interrupt when done. SCL stays low. Seems to be an issue people are running into. 23 | * 24 | * 25 | */ 26 | int I2C_Write_Data(uint8_t i2c_port, uint8_t devAddr, u8 *TxMsgPtr, int ByteCount); 27 | int I2C_Read_Data(uint8_t i2c_port, uint8_t devAddr, uint8_t regAddr, uint8_t *RxMsgPtr, int ByteCount); 28 | 29 | #endif /* SRC_I2C_READWRITE_H_ */ 30 | -------------------------------------------------------------------------------- /TI/I2C_TM4C.h: -------------------------------------------------------------------------------- 1 | /* 2 | * i2c_hal.h 3 | * 4 | * Created on: Mar 5, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef I2C_HAL_H_ 9 | #define I2C_HAL_H_ 10 | 11 | #include "main.h" 12 | 13 | // I2C defines 14 | #ifndef _I2C_BUFFER_DEFINES 15 | #define _I2C_BUFFER_DEFINES 16 | #define MAX_I2C_DATA_BUFFER 2// 2 bytes, register and data byte 17 | #define MAX_I2C_MESSAGE_BUFFER 2 18 | #endif 19 | 20 | 21 | #define I2C_TIMEOUT 125 22 | 23 | 24 | typedef union { 25 | struct{ 26 | uint8_t data[2]; 27 | }Data; 28 | struct{ 29 | uint8_t i2c_register; 30 | uint8_t data; 31 | }Status; 32 | }I2C_DataStruct; 33 | 34 | 35 | int I2C_Master_Receive(uint32_t i2c_base, uint16_t DevAddress, uint8_t *pData, uint32_t size); 36 | int I2C_Master_Transmit(uint32_t i2c_base, uint16_t DevAddress, uint8_t *pData, uint32_t size); 37 | int I2C_Master_ReadRegister(uint32_t i2c_base, uint16_t DevAddress, uint8_t *regAddress, uint32_t regSize, uint8_t *pData_OUT, uint32_t size); 38 | int I2C_EV_IRQHandler(uint32_t i2c_base); 39 | 40 | 41 | #endif /* I2C_HAL_H_ */ 42 | -------------------------------------------------------------------------------- /TMP10x_Handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TMP10x_Handler.h 3 | * 4 | * Created on: Apr 24, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_TMP10X_HANDLER_H_ 9 | #define INC_TMP10X_HANDLER_H_ 10 | 11 | // HAL driver requires the slave address be shifted to the left by 1. 12 | #define TMP10x_SLAVE_ADDRESS_00 0b1001000 // 0x48 13 | #define TMP10x_SLAVE_ADDRESS_01 0b1001010 // 0x4A 14 | 15 | 16 | int TMP10x_Init(I2C_GenericDef *i2c); 17 | 18 | int TMP10x_GetRegisterHandle(I2C_GenericDef *i2c, char *msg, char *retStr); 19 | int TMP10x_SetRegisterHandle(I2C_GenericDef *i2c, char *msg); 20 | 21 | int TMP10x_SetThermostatMode(I2C_GenericDef *i2c, char *msg); 22 | 23 | void TMP101_GetTemperatureString(uint8_t *tmp101Value, char *retStr); 24 | void TMP10x_SwapBytes(uint8_t *data); 25 | 26 | // USER can create callbacks prototypes here 27 | void TMP10x_TemperatureCallback(I2C_GenericDef *i2c); 28 | void TMP10x_ConfigCallback(I2C_GenericDef *i2c); 29 | void TMP10x_LowCallback(I2C_GenericDef *i2c); 30 | void TMP10x_HighCallback(I2C_GenericDef *i2c); 31 | 32 | #endif /* INC_TMP10X_HANDLER_H_ */ 33 | -------------------------------------------------------------------------------- /ErrorStatus.h: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | * @attention 4 | * 5 | * Copyright (c) 2025 Karl Yamashita 6 | * All rights reserved. 7 | * 8 | * This software is licensed under terms that can be found in the LICENSE file 9 | * in the root directory of this software component. 10 | * If no LICENSE file comes with this software, it is provided AS-IS. 11 | * 12 | ****************************************************************************** 13 | */ 14 | 15 | /* 16 | * ErrorStatus.h 17 | * 18 | * Created on: Nov 24, 2021 19 | * Author: karl.yamashita 20 | */ 21 | 22 | #ifndef ERRORSTATUS_H_ 23 | #define ERRORSTATUS_H_ 24 | 25 | 26 | // error status 27 | enum { 28 | RETURN_DATA = -2, 29 | NO_ACK = -1, 30 | NO_ERROR, 31 | COMMAND_UNKNOWN, 32 | VALUE_OUT_OF_RANGE, 33 | VALUE_NOT_VALID, 34 | 35 | // for debug 36 | ERR_1 = 200, 37 | ERR_2, 38 | ERR_3, 39 | ERR_4 40 | }; 41 | 42 | 43 | 44 | void GetErrorString(int errorCode, char *str); 45 | 46 | #endif /* ERRORSTATUS_H_ */ 47 | -------------------------------------------------------------------------------- /TCA9546A_Drv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * TCA9546A_Drv.c 3 | * 4 | * Created on: Jun 21, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | 9 | #include "main.h" 10 | 11 | 12 | void TCA9546A_Init(TCA9546A_HandlerTypeDef *tca, I2C_GenericDef *i2c, uint32_t transferType) 13 | { 14 | tca->i2c_Instance = i2c; 15 | tca->i2c_Instance->timeout = 100; 16 | tca->i2c_Instance->transferType = transferType; 17 | } 18 | 19 | 20 | int TCA9546A_Write(TCA9546A_HandlerTypeDef *tca, void (*callback)) 21 | { 22 | int status = NO_ERROR; 23 | 24 | tca->i2c_Instance->dataSize = 1; 25 | tca->RxISR = callback; 26 | 27 | status = I2C_Master_Transmit_Generic(tca->i2c_Instance); 28 | 29 | return status; 30 | } 31 | 32 | /* 33 | * Description: Query TCA9546A for which channel is selected 34 | * Input: none 35 | * Output: Channel number 36 | */ 37 | int TCA9546A_Read(TCA9546A_HandlerTypeDef *tca, void (*callback)) 38 | { 39 | int status = NO_ERROR; 40 | 41 | tca->i2c_Instance->dataSize = 1; 42 | tca->RxISR = callback; 43 | 44 | status = I2C_Master_Receive_Generic(tca->i2c_Instance); 45 | 46 | return status; 47 | } 48 | -------------------------------------------------------------------------------- /DebugMode.c: -------------------------------------------------------------------------------- 1 | 2 | #include "main.h" 3 | #include "DebugMode.h" 4 | 5 | 6 | DebugModeStructure debugTelemetry; 7 | 8 | 9 | int DEBUG_Mode(char *msg) 10 | { 11 | int status = NO_ERROR; 12 | char *token; 13 | char *token2; 14 | // char *token3; 15 | char *rest = msg; 16 | 17 | token = strtok(rest, ","); // debug pointer 18 | token2 = strtok(NULL, "\r"); // enable 19 | // token3 = strtok_r(rest, "\r", &rest); // value 20 | 21 | 22 | switch(atoi(token)) 23 | { 24 | case 0: 25 | debugTelemetry.enable = atoi(token2); 26 | break; 27 | case 1: 28 | 29 | break; 30 | case 2: 31 | 32 | break; 33 | case 3: 34 | 35 | break; 36 | case 4: 37 | 38 | break; 39 | case 5: 40 | 41 | break; 42 | case 6: 43 | 44 | break; 45 | case 7: 46 | 47 | break; 48 | default: 49 | break; 50 | } 51 | 52 | 53 | return status; 54 | } 55 | -------------------------------------------------------------------------------- /Vehicle Drivers/Lighting.h: -------------------------------------------------------------------------------- 1 | #ifdef USE_LIGHTING 2 | #ifndef LIGHTING_H 3 | #define LIGHTING_H 4 | 5 | #if defined GMLAN_V1 6 | typedef union LightingStatus { 7 | struct{ 8 | uint8_t byte1; 9 | uint8_t byte0; 10 | }Bytes; 11 | struct{ 12 | //byte1 13 | unsigned turnSwitchActivation:2; 14 | unsigned rightTurnSignalActive:2; 15 | unsigned leftTurnSignalActive:2; 16 | unsigned :2; 17 | //byte0 18 | unsigned lowBeamActive:1; 19 | unsigned parkingLightsActive:1; 20 | unsigned highBeamActive:1; 21 | unsigned highBeamIndicationOn:1; 22 | unsigned groundIlluminationRequest:1; 23 | unsigned frontFogLampsActive:1; 24 | unsigned flashToPassActive:1; 25 | unsigned dayTimeRunningLightsActive:1; 26 | }Status; 27 | }LightingStatus; 28 | 29 | #endif // GMLAN_V1 30 | 31 | #if defined CHRYSLER_V3 32 | typedef struct LightingStatus { 33 | unsigned :7; 34 | unsigned ParkingLightsActive:1; 35 | }LightingStatus; 36 | 37 | #endif// CHRYSLER_V3 38 | 39 | void ServiceLightingStatus(uint8_t *data); 40 | 41 | LightingStatus GetLightingStatus(void); 42 | 43 | #endif // LIGHTING_H 44 | #endif // USE_LIGHTING 45 | -------------------------------------------------------------------------------- /ADC_Buffer_Handler_STM32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ADC_Buffer_Handler.h 3 | * 4 | * Created on: Mar 1, 2025 5 | * Author: codek 6 | */ 7 | 8 | #ifndef INC_ADC_BUFFER_HANDLER_STM32_H_ 9 | #define INC_ADC_BUFFER_HANDLER_STM32_H_ 10 | 11 | 12 | 13 | enum 14 | { 15 | ADC_NO_ERROR, 16 | ADC_ERROR_INSTANCE_FULL 17 | }; 18 | 19 | #define ADC_INSTANCE_SIZE 2 20 | 21 | 22 | typedef struct 23 | { 24 | uint16_t *buffer; 25 | uint32_t bufferSize; 26 | uint16_t average; 27 | RING_BUFF_STRUCT ptr; 28 | }ADC_Buffer_Instance_t; 29 | 30 | typedef struct 31 | { 32 | ADC_HandleTypeDef *hadc; 33 | uint16_t *DMA_Buffer; 34 | ADC_Buffer_Instance_t *instance[ADC_INSTANCE_SIZE]; 35 | uint32_t adcInstanceSize; 36 | uint32_t errorStatus; 37 | bool rdyFlag; 38 | }ADC_Buffer_t; 39 | 40 | 41 | 42 | int ADC_Buffer_Register(ADC_Buffer_t *adcBuffer, ADC_Buffer_Instance_t *adc_i); 43 | int ADC_StartDMA(ADC_Buffer_t *adc); 44 | int ADC_ConversionCheck(ADC_Buffer_t *adcBuffer); 45 | uint16_t ADC_GetAverage(ADC_Buffer_Instance_t *adc_i); 46 | int ADC_SetRdyFlag(ADC_Buffer_t *adcBuffer); 47 | 48 | 49 | #endif /* INC_ADC_BUFFER_HANDLER_STM32_H_ */ 50 | -------------------------------------------------------------------------------- /INA3221_Drv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * INA3221_Drv.c 3 | * 4 | * Created on: Jun 15, 2024 5 | * Author: codek 6 | */ 7 | 8 | #include "main.h" 9 | 10 | /* 11 | * Description: Read INA3221 register and call the callback if registered. 12 | * 13 | */ 14 | int INA3221_Read(I2C_GenericDef *i2c, uint16_t reg, void (*callback)(struct __I2C_GenericDef_ *i2c)) 15 | { 16 | int status = NO_ERROR; 17 | 18 | i2c->registerAddr[0] = reg; 19 | i2c->regSize = 1; 20 | i2c->RxISR = callback; 21 | 22 | status = I2C_Mem_Read_Generic_Method(i2c); 23 | if(status != NO_ERROR) 24 | { 25 | return status; 26 | } 27 | 28 | return status; 29 | } 30 | 31 | /* 32 | * Description: Be sure to initialize I2C data pointer with data and data size prior to calling this. 33 | */ 34 | int INA3221_Write(I2C_GenericDef *i2c, uint16_t reg, void (*callback)(struct __I2C_GenericDef_ *i2c)) 35 | { 36 | int status = NO_ERROR; 37 | 38 | i2c->registerAddr[0] = reg; 39 | i2c->regSize = 1; 40 | i2c->TxISR = callback; 41 | 42 | status = I2C_Mem_Write_Generic_Method(i2c); 43 | if(status != NO_ERROR) 44 | { 45 | return status; 46 | } 47 | 48 | return status; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /Vehicle Drivers/ArbTextDisplayStatus.h: -------------------------------------------------------------------------------- 1 | #ifndef ARB_TEXT_DISPLAY_STATUS_H 2 | #define ARB_TEXT_DISPLAY_STATUS_H 3 | 4 | #include "main.h" 5 | 6 | typedef union ArbTextDisplayStatus{ 7 | struct { 8 | uint8_t byte3; 9 | uint8_t byte2; 10 | uint8_t byte1; 11 | uint8_t byte0; 12 | }Bytes; 13 | struct{ 14 | unsigned char messageOperationStatus; 15 | unsigned char iconIdentifier; 16 | unsigned sessionIdentifier:3; 17 | unsigned requestingDeviceIdentifier:3; 18 | unsigned displayDeviceIdentifier:4; 19 | unsigned :6; 20 | }Status; 21 | }ArbTextDisplayStatus; 22 | 23 | typedef struct DisplayStatus { 24 | bool displayTurnedOffUnavailable; 25 | bool invalidDataLength; 26 | bool invalidData; 27 | bool requestedDisplayNowOff; 28 | bool requestedDisplayNowOn; 29 | bool displayAvailable; 30 | bool dataTransferNotGranted; 31 | bool dataTransferGranted; 32 | }DisplayStatus; 33 | 34 | bool ServiceArbTextDisplayStatus(uint8_t *data); 35 | ArbTextDisplayStatus GetArbTextDisplayStatus(void); 36 | 37 | 38 | void SendArbTextDisplayStatus(ArbTextDisplayStatus *arbTextDisplayStatus); 39 | 40 | 41 | #endif // ARB_TEXT_DISPLAY_STATUS_H 42 | -------------------------------------------------------------------------------- /TCA9546A_Drv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TCA9546A_Drv.h 3 | * 4 | * Created on: Jun 21, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_TCA9546A_DRV_H_ 9 | #define INC_TCA9546A_DRV_H_ 10 | 11 | 12 | #define TCA9546A_ADDRESS_70 (uint8_t)0b1110000 // 0x70, south board 13 | #define TCA9546A_ADDRESS_74 (uint8_t)0b1110100 // 0x74, north board 14 | 15 | 16 | #define TCA9546A_CHANNEL_1 0x01 17 | #define TCA9546A_CHANNEL_2 0x04 // schematic error, needs to be 0x04 18 | #define TCA9546A_CHANNEL_3 0x02 // schematic error, needs to be 0x02 19 | #define TCA9546A_CHANNEL_4 0x08 20 | #define TCA9546A_CHANNELS_RESET 0 21 | 22 | 23 | typedef struct __TCA9546A_HandlerTypeDef 24 | { 25 | char *commandCopy; 26 | 27 | I2C_GenericDef *i2c_Instance; 28 | void (*RxISR)(struct __TCA9546A_HandlerTypeDef *tca); // callback 29 | } TCA9546A_HandlerTypeDef; 30 | 31 | void TCA9546A_Init(TCA9546A_HandlerTypeDef *tca, I2C_GenericDef *i2c, uint32_t transferType); 32 | 33 | int TCA9546A_Write(TCA9546A_HandlerTypeDef *tca, void (*callback)); 34 | int TCA9546A_Read(TCA9546A_HandlerTypeDef *tca, void (*callback)); 35 | 36 | 37 | #endif /* INC_TCA9546A_DRV_H_ */ 38 | -------------------------------------------------------------------------------- /Vehicle Drivers/CAN_MessageDelayed.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_CAN_MESSAGE_DELAYED 3 | #ifndef CAN_MESSAGE_DELAY_H 4 | #define CAN_MESSAGE_DELAY_H 5 | 6 | #include "CAN.h" 7 | 8 | 9 | typedef struct CAN_MessageDelayedStructure { 10 | CanTxMsgTypeDef canMessage; 11 | uint32_t delay; 12 | }CAN_MessageDelayedStructure; 13 | 14 | 15 | /* 16 | function: Places the message in CAN1 buffer with delay into a structure to be compared in 17 | CheckCAN_DelayMessageBuffer1() function. 18 | input: the CAN message and the delay before sending on CAN bus 19 | output: none 20 | note: This added message will start it's delay after all previous messages are sent. 21 | */ 22 | void AddDelayedCAN1_MessageToBuffer(CanTxMsgTypeDef *canMessage, uint32_t delay); 23 | void AddDelayedCAN2_MessageToBuffer(CanTxMsgTypeDef *canMessage, uint32_t delay); 24 | 25 | /* 26 | function: Check if specific message delay is reached then place message in CAN1 Tx buffer 27 | input: none 28 | output: none 29 | */ 30 | void CheckCAN1_DelayMessageBuffer(void); 31 | void CheckCAN2_DelayMessageBuffer(void); 32 | 33 | #endif // CAN_MESSAGE_DELAY_H 34 | #endif // USE_CAN_MESSAGE_DELAY 35 | -------------------------------------------------------------------------------- /STM32_UID.c: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | * @attention 4 | * 5 | * Copyright (c) 2025 Karl Yamashita 6 | * All rights reserved. 7 | * 8 | * This software is licensed under terms that can be found in the LICENSE file 9 | * in the root directory of this software component. 10 | * If no LICENSE file comes with this software, it is provided AS-IS. 11 | * 12 | ****************************************************************************** 13 | */ 14 | 15 | /* 16 | * STM32_UID.c 17 | * 18 | * Created on: Sep 3, 2025 19 | * Author: codek 20 | */ 21 | 22 | 23 | #include "main.h" 24 | 25 | 26 | STM32_UID_t stm32_uid = {0}; 27 | 28 | 29 | int STM32_UID_Get(char *retStr) 30 | { 31 | int status = NO_ERROR; 32 | 33 | STM32_UID(&stm32_uid); 34 | 35 | sprintf(retStr, "0x%08lX%08lX%08lX", stm32_uid.high, (uint32_t) (stm32_uid.low >> 32), (uint32_t) stm32_uid.low); 36 | 37 | return status; 38 | } 39 | 40 | 41 | void STM32_UID(STM32_UID_t *msg) 42 | { 43 | msg->UID_t.uid_0 = HAL_GetUIDw0(); 44 | msg->UID_t.uid_1 = HAL_GetUIDw1(); 45 | msg->UID_t.uid_2 = HAL_GetUIDw2(); 46 | } 47 | 48 | 49 | -------------------------------------------------------------------------------- /Vehicle Drivers/DiagnosticTool.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_DIAGNOSTIC_TOOL 3 | 4 | #include "main.h" 5 | #include "DiagnosticTool.h" 6 | #include "can.h" 7 | 8 | unsigned char diagnosticStatus[8]; 9 | unsigned char diagnosticToolFlag = 0; 10 | unsigned char stopCommunicationsFlag = 0; 11 | 12 | void ServiceDiagnosticTool(unsigned char *data) { 13 | int i; 14 | for(i = 0; i < 8; i++){ 15 | diagnosticStatus[i] = data[i]; 16 | } 17 | diagnosticToolFlag = 1; 18 | } 19 | 20 | void CheckDiagnosticTool(callbackDiagnosticTool diagnosticToolCallback) { 21 | if(!diagnosticToolFlag) return; 22 | diagnosticToolFlag = 0; 23 | diagnosticToolCallback(diagnosticStatus); 24 | } 25 | 26 | void DiagnosticToolCallback(unsigned char *status) { 27 | static unsigned char oldStatus[8]; 28 | if(memcmp(oldStatus, status,8) == 0) { 29 | return; 30 | } 31 | 32 | // stop communicating until bus is quiet for 20 seconds. 33 | if(status[1] == 0x34) { 34 | stopCommunicationsFlag = 1; 35 | } else { 36 | stopCommunicationsFlag = 0; 37 | } 38 | } 39 | 40 | unsigned char GetDiagnosticToolStatus(void) { 41 | return stopCommunicationsFlag; 42 | } 43 | 44 | #endif // USE_DIAGNOSTIC_TOOL 45 | 46 | 47 | -------------------------------------------------------------------------------- /Xilinx/GPIO_Init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GPIO_Init.h 3 | * 4 | * Created on: Jun 4, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SRC_GPIO_INIT_H_ 9 | #define SRC_GPIO_INIT_H_ 10 | 11 | #define CHANNEL_1 1 12 | #define CHANNEL_2 2 13 | 14 | // pins config for RDRVR 15 | enum { 16 | Pin_C6_CFG1_S1, 17 | Pin_B6_CFG1_S2, 18 | Pin_C3_CFG2_S1, 19 | Pin_A4_CFG2_S2, 20 | Pin_C5_RX_EQ1_S1, 21 | Pin_A5_RX_EQ1_S2, 22 | Pin_B2_RX_EQ2_S1, 23 | Pin_B1_RX_EQ2_S2, 24 | Pin_F11_TX_EQ1_S1, 25 | Pin_D12_TX_EQ1_S2, 26 | Pin_F13_TX_EQ2_S1, 27 | Pin_E12_TX_EQ2_S2, 28 | 29 | Pin_D2_CFG1_S1, 30 | Pin_E1_CFG1_S2, 31 | Pin_C1_CFG2_S1, 32 | Pin_D4_CFG2_S2, 33 | Pin_H5_RX_EQ1_S1, 34 | Pin_H4_RX_EQ1_S2, 35 | Pin_J6_RX_EQ2_S1, 36 | Pin_G4_RX_EQ2_S2, 37 | Pin_T8_TX_EQ1_S1, 38 | Pin_W7_TX_EQ1_S2, 39 | Pin_H6_TX_EQ2_S1, 40 | Pin_K4_TX_EQ2_S2, 41 | }; 42 | 43 | enum{ 44 | Pin_D21_SSMUX1_OEn, 45 | Pin_D20_SSMUX1_PDn, 46 | Pin_G20_SSMUX1_SEL1, 47 | Pin_F22_SSMUX1_SEL2, 48 | Pin_E22_SSMUX2_OEn, 49 | Pin_F12_SSMUX2_PDn, 50 | Pin_F4_SSMUX2_SEL1, 51 | Pin_A17_SSMUX2_SEL2, 52 | }; 53 | 54 | 55 | 56 | int Init_GPIO(void); 57 | void GPIO_Init_Direction(void); 58 | 59 | 60 | #endif /* SRC_GPIO_INIT_H_ */ 61 | -------------------------------------------------------------------------------- /Radio Drivers/RadioFunctions.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_RADIO_FUNCTIONS 3 | #include "main.h" 4 | #include "RadioFunctions.h" 5 | #include "Clarion.h" 6 | #include "Kenwood.h" 7 | #include "Alpine.h" 8 | #include "JVC.h" 9 | 10 | 11 | uint8_t swcRadioTable[4][16] = { 12 | {ALPINE_VOLUME_UP, ALPINE_VOLUME_DOWN, ALPINE_MUTE, ALPINE_SOURCE}, 13 | {CLARION_VOLUME_UP, CLARION_VOLUME_DOWN, CLARION_MUTE, CLARION_SOURCE}, 14 | {KENWOOD_VOLUME_UP, KENWOOD_VOLUME_DOWN, KENWOOD_ATT, KENWOOD_SOURCE}, 15 | {JVC_VOLUME_UP, JVC_VOLUME_DOWN, JVC_ATT, JVC_SOURCE}, 16 | }; 17 | 18 | void RadioCommands(uint8_t command){ 19 | // todo get radio type 20 | switch(2) { // radio type 21 | case 0: 22 | AlpineCommand(command); 23 | break; 24 | case 1: 25 | // ClarionCommand(command); 26 | break; 27 | case 2: 28 | KenwoodCommand(command); 29 | break; 30 | case 3: 31 | JVC_Command(command); 32 | break; 33 | case 4: 34 | //PioneerCommand(command); 35 | break; 36 | case 5: 37 | //SonyCommand(command); 38 | break; 39 | case 6: 40 | //Sony2Command(command); 41 | break; 42 | default: 43 | break; 44 | } 45 | // todo delay 108 ms between commands 46 | } 47 | #endif // USE_RADIO_FUNCTIONS 48 | -------------------------------------------------------------------------------- /Vehicle Drivers/Doors.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_DOORS 3 | #include "main.h" 4 | #include "Doors.h" 5 | 6 | #if defined GMLAN_V1 7 | 8 | union DriverDoorStatus 9 | { 10 | unsigned char StatusByte; 11 | struct 12 | { 13 | unsigned OpenSwitchActive:1; 14 | unsigned AjarSwitchActive:1; 15 | }Bits; 16 | }DriverDoorStatus; 17 | #define _DriverDoorStatus DriverDoorStatus.StatusByte 18 | #define _DriverDoorOpenSwitchActive DriverDoorStatus.Bits.OpenSwitchActive 19 | #define _DriverDoorAjarSwitchActive DriverDoorStatus.Bits.AjarSwitchActive // most other cars only use bit0 to indicate door open 20 | 21 | void ServiceDriversDoorStatus(unsigned char *data){ 22 | DriverDoorStatus.StatusByte = data[0]; 23 | } 24 | 25 | void ServicePassengerDoorStatus(unsigned char *data){ 26 | 27 | } 28 | 29 | bool GetDriversDoorStatus(void){ 30 | return _DriverDoorAjarSwitchActive; 31 | } 32 | 33 | #endif // GMLAN_V1 34 | 35 | #if defined CHRYSLER_V3 36 | 37 | void ServiceDriversDoorStatus(unsigned char *data){ 38 | DriverDoorStatus.StatusByte = data[0]; 39 | } 40 | 41 | bool GetDriversDoorStatus(void){ 42 | return _DriverDoorAjarSwitchActive; 43 | } 44 | 45 | 46 | 47 | #endif// CHRYSLER_V4 48 | #endif // USE_DOORS 49 | 50 | -------------------------------------------------------------------------------- /CANFD_Buffer.h: -------------------------------------------------------------------------------- 1 | #ifndef CANFD_BUFFER_H 2 | #define CANFD_BUFFER_H 3 | 4 | 5 | 6 | // Receive 7 | typedef struct 8 | { 9 | FDCAN_RxHeaderTypeDef header; 10 | uint8_t data[64]; 11 | }CANFD_RxMsgTypeDef; 12 | 13 | // Transmit 14 | typedef struct 15 | { 16 | FDCAN_TxHeaderTypeDef header; 17 | uint8_t data[64]; 18 | }CANFD_TxMsgTypeDef; 19 | 20 | typedef struct 21 | { 22 | FDCAN_HandleTypeDef *hfdcan; // CAN instance 23 | 24 | // Rx 25 | CANFD_RxMsgTypeDef *rxQueue; 26 | uint32_t rxQueueSize; 27 | CANFD_RxMsgTypeDef *msgToParse; // pointer to latest queue 28 | RING_BUFF_STRUCT rxPtr; // queue pointer 29 | bool canBusActive; // used for CAN bus activity to keep STM32 from going to sleep. 30 | // Tx 31 | CANFD_TxMsgTypeDef *txQueue; 32 | uint32_t txQueueSize; 33 | RING_BUFF_STRUCT txPtr; // queue pointer 34 | }CANFD_MsgStruct; 35 | 36 | int CANFD_SendMessage(CANFD_MsgStruct *msg); 37 | int CANFD_AddTxBuffer(CANFD_MsgStruct *msg, CANFD_TxMsgTypeDef *txData); 38 | bool CANFD_DataAvailable(CANFD_MsgStruct *msg); 39 | bool CANFD_GetBusActivity(CANFD_MsgStruct *msg); 40 | void CANFD_ClearBusActivity(CANFD_MsgStruct *msg); 41 | void CANFD_MsgCopy(CANFD_TxMsgTypeDef *TxMsg, CANFD_RxMsgTypeDef *RxMsg); 42 | 43 | #endif // CAN_BUFFER_H 44 | 45 | -------------------------------------------------------------------------------- /Vehicle Drivers/CAN_BufferV3.h: -------------------------------------------------------------------------------- 1 | #ifndef CAN_BUFFER_V3_H 2 | #define CAN_BUFFER_V3_H 3 | 4 | 5 | // typically this will be 8 6 | #define CAN_DATA_BUFF_SIZE 8 7 | 8 | // increase if buffer over run. 9 | #define CAN_RX_QUEUE_SIZE 4 10 | #define CAN_TX_QUEUE_SIZE 4 11 | 12 | // rxMsg buffer 13 | typedef struct 14 | { 15 | CAN_RxHeaderTypeDef header; 16 | uint8_t data[CAN_DATA_BUFF_SIZE]; 17 | }CanRx; 18 | 19 | // txMsg buffer 20 | typedef struct 21 | { 22 | CAN_TxHeaderTypeDef header; 23 | uint8_t data[CAN_DATA_BUFF_SIZE]; 24 | }CanTx; 25 | 26 | typedef struct 27 | { 28 | CAN_HandleTypeDef *hcan; 29 | struct 30 | { 31 | CanRx queue[CAN_RX_QUEUE_SIZE]; 32 | CanRx *msgToParse; 33 | uint32_t msgQueueSize; 34 | RING_BUFF_STRUCT ptr; 35 | }rx; 36 | 37 | struct 38 | { 39 | CanTx queue[CAN_TX_QUEUE_SIZE]; 40 | uint32_t msgQueueSize; 41 | RING_BUFF_STRUCT ptr; 42 | }tx; 43 | 44 | bool canBusActive; 45 | }CanMsg_Struct; 46 | 47 | void CAN_IncRxBuffer(CanMsg_Struct *msg); 48 | int CAN_MsgAvailable(CanMsg_Struct *msg); 49 | void CAN_AddTxBuffer(CanMsg_Struct *msg, CanTx *canMsg); 50 | void CAN_SendTxMessage(CanMsg_Struct *canMsg); 51 | 52 | #endif // CAN_BUFFER_V3_H 53 | -------------------------------------------------------------------------------- /FDCAN_Handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FDCAN_Handler.h 3 | * 4 | * Created on: Oct 7, 2023 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_FDCAN_HANDLER_H_ 9 | #define INC_FDCAN_HANDLER_H_ 10 | 11 | 12 | #define FDCAN_RX_BUF_SIZE 8 13 | #define FDCAN_TX_BUF_SIZE 4 14 | 15 | 16 | typedef struct 17 | { 18 | FDCAN_RxHeaderTypeDef *pRxHeader; 19 | uint8_t data[64]; 20 | }FDCAN_Rx; 21 | 22 | typedef struct 23 | { 24 | FDCAN_TxHeaderTypeDef pTxHeader; 25 | uint8_t data[64]; 26 | }FDCAN_Tx; 27 | 28 | 29 | typedef struct 30 | { 31 | struct 32 | { 33 | FDCAN_HandleTypeDef *fdcan; 34 | FDCAN_Rx queue[FDCAN_RX_BUF_SIZE]; 35 | FDCAN_Rx *msgToParse; 36 | RING_BUFF_STRUCT ptr; 37 | uint32_t queueSize; 38 | }rx; 39 | struct 40 | { 41 | FDCAN_HandleTypeDef *fdcan; 42 | FDCAN_Tx queue[FDCAN_TX_BUF_SIZE]; 43 | RING_BUFF_STRUCT ptr; 44 | uint32_t queueSize; 45 | }tx; 46 | 47 | }FDCAN_Buffer; 48 | 49 | 50 | void FDCAN_InitInstance(FDCAN_Buffer *fdcanBuffer, FDCAN_HandleTypeDef *fdcan); 51 | 52 | void FDCAN_AddToRxBuffer(FDCAN_Buffer *fdcanBuffer, FDCAN_Rx *rxData); 53 | 54 | void FDCAN_AddDataToTxBuffer(FDCAN_Buffer *fdcanBuffer, FDCAN_Tx *data); 55 | void FDCAN_Transmit(FDCAN_Buffer *fdcanBuffer); 56 | 57 | 58 | #endif /* INC_FDCAN_HANDLER_H_ */ 59 | -------------------------------------------------------------------------------- /RingBuffer.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | ****************************************************************************** 4 | * @attention 5 | * 6 | * Copyright (c) 2025 Karl Yamashita 7 | * All rights reserved. 8 | * 9 | * This software is licensed under terms that can be found in the LICENSE file 10 | * in the root directory of this software component. 11 | * If no LICENSE file comes with this software, it is provided AS-IS. 12 | * 13 | ****************************************************************************** 14 | */ 15 | 16 | #ifndef RING_BUFFER_H 17 | #define RING_BUFFER_H 18 | 19 | #include "main.h" 20 | 21 | #define RING_BUFF_OVERFLOW_SIZE 100 22 | 23 | typedef struct 24 | { 25 | uint32_t index_IN; // pointer to where the data will be save to 26 | uint32_t index_OUT; // pointer to next available data in buffer if cnt_handle is not zero 27 | uint32_t cnt_Handle; // if not zero then message available 28 | uint32_t cnt_OverFlow; // has overflow if not zero 29 | uint8_t SkipOverFlow; 30 | }RING_BUFF_STRUCT; 31 | 32 | void RingBuff_Ptr_Reset(RING_BUFF_STRUCT *ptr); 33 | int RingBuff_Ptr_Input(RING_BUFF_STRUCT *ptr, uint32_t bufferSize); 34 | int RingBuff_Ptr_Output(RING_BUFF_STRUCT *ptr, uint32_t bufferSize); 35 | 36 | 37 | 38 | #endif // RING_BUFFER_H 39 | -------------------------------------------------------------------------------- /Xilinx/GPIO_ReadWrite.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GPIO_ReadWrite.c 3 | 4 | * 5 | * Created on: Jul 27, 2021 6 | * Author: karl.yamashita 7 | */ 8 | 9 | #include "main.h" 10 | #include "GPIO_ReadWrite.h" 11 | 12 | 13 | extern XGpio Gpio_0; /* The Instance of the GPIO Driver */ 14 | extern XGpio Gpio_1; /* The Instance of the GPIO Driver */ 15 | extern XGpio Gpio_2; /* The Instance of the GPIO Driver */ 16 | 17 | 18 | 19 | /* 20 | * Description: 21 | * 22 | * 23 | * 24 | */ 25 | void GPIO_Read(XGpio *gpio, uint8_t channel, uint32_t *pins_OUT){ 26 | *pins_OUT = XGpio_DiscreteRead(gpio, channel); 27 | } 28 | 29 | /* 30 | * Description: writes value to the pins 31 | * 32 | * 33 | */ 34 | void GPIO_Write(XGpio *gpio, uint8_t channel, uint32_t *pins){ 35 | XGpio_DiscreteWrite(gpio, channel, (uint32_t)pins); 36 | } 37 | 38 | /* 39 | * Description: Sets the pins 40 | * 41 | * 42 | */ 43 | void GPIO_Set(XGpio *gpio, uint8_t channel, uint32_t *pins){ 44 | XGpio_DiscreteSet(gpio, channel, (uint32_t)pins); 45 | } 46 | 47 | /* 48 | * Description: Clears the pins 49 | * Input: The GPIO instance and the pin mask 50 | * 51 | */ 52 | void GPIO_Clear(XGpio *gpio, uint8_t channel, uint32_t *pins){ 53 | XGpio_DiscreteClear(gpio, channel, (uint32_t)pins); 54 | } 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /Interpolation_Drv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Interpolation.h 3 | * 4 | * Created on: May 22, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_INTERPOLATION_DRV_H_ 9 | #define INC_INTERPOLATION_DRV_H_ 10 | 11 | // un-comment if you want to enable extrapolation. This allows X and Y values to go beyond X2 and Y2 values. 12 | //#define EXTRAPOLATION_ALLOWED 13 | 14 | typedef struct 15 | { 16 | float y; // calculated requested value 17 | float x; // requested value 18 | float x1; // typically is zero 19 | float x2; // target value 20 | float y1; // typically is zero 21 | float y2; // calculated value, difference between x2 and y2_offset 22 | float y2_offset; // DMM measured value 23 | uint8_t type; 24 | }Interpolation_t; 25 | 26 | int Interpolation_Get_Y(Interpolation_t *interpol, float x); 27 | int Interpolation_Set_X1_X2(Interpolation_t *interpol, float _x1, float _x2); 28 | int Interpolation_Set_Y1_Y2(Interpolation_t *interpol, float _y1, float _y2); 29 | int Interpolation_Set_X(Interpolation_t *interpol, float _x); 30 | int Interpolation_GetMsg_X(Interpolation_t *interpol, char *retStr); 31 | int Interpolation_GetMsg_Y(Interpolation_t *interpol, char *retStr); 32 | int Interpolation_SetMsg(Interpolation_t *interpol, char *msg); 33 | 34 | 35 | #endif /* INC_INTERPOLATION_DRV_H_ */ 36 | -------------------------------------------------------------------------------- /Modulo256Checksum.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Modulo256Checksum.c 3 | * 4 | * Created on: May 13, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #include "main.h" 9 | #include "Modulo256Checksum.h" 10 | 11 | /* 12 | * Description: Validate checksum using modulo 256 13 | * Input: the data array and the length of array including the checksum 14 | * Output: true if valid checksum else false 15 | * 16 | */ 17 | int ValidateChkSum(uint8_t *data, uint8_t len){ 18 | uint32_t chksum = 0; 19 | uint32_t i = 0; 20 | 21 | for(i = 0; i < len - 1; i++) 22 | { 23 | chksum += *data++; 24 | } 25 | if((chksum % 256) != *data) 26 | { 27 | return 1; // bad checksum 28 | } 29 | 30 | return 0; // good checksum 31 | } 32 | 33 | /* 34 | * Description: Calculate checksum using modulo 256 and adds checksum to array at last index + 1 35 | * Input: The data array and the length of array minus the checksum index 36 | * Output: 37 | * 38 | */ 39 | void CalculateChkSum(uint8_t *data, uint8_t len) 40 | { 41 | uint32_t chksum = 0; 42 | uint32_t i = 0; 43 | 44 | for (i = 0; i < len - 1; i++) 45 | { 46 | chksum += *data++; 47 | } 48 | *data = (chksum % 256); // copy checksum to last index 49 | } 50 | 51 | -------------------------------------------------------------------------------- /Vehicle Drivers/RemoteReceiverStatus.h: -------------------------------------------------------------------------------- 1 | #ifndef REMOTE_RECEIVER_STATUS_H 2 | #define REMOTE_RECEIVER_STATUS_H 3 | 4 | typedef union RemoteReceiverStatus { 5 | struct { 6 | uint8_t byte7; 7 | uint8_t byte6; 8 | uint8_t byte5; 9 | uint8_t byte4; 10 | uint8_t byte3; 11 | uint8_t byte2; 12 | uint8_t byte1; 13 | uint8_t byte0; 14 | }Bytes; 15 | struct{ 16 | unsigned currentAudioProgramServiceIdentifier:8; 17 | unsigned serviceProvider :3; 18 | unsigned receiverType :4; 19 | unsigned :1; 20 | unsigned receiverTrafficInterruptStatus:3; 21 | unsigned receiverSeekingStatus:4; 22 | unsigned :1; 23 | unsigned receiverTuningStatus:1; 24 | unsigned receiverEmergencyInterruptStatus:3; 25 | unsigned receiverScanningStatus:4; 26 | unsigned currentTunedStation:16; 27 | unsigned receiverInformationAvailableActive:1; 28 | unsigned receiverInitialinzingActive:1; 29 | unsigned receiverCommandStatus:3; 30 | unsigned receiverDataType:3; 31 | unsigned currentStationQuality:1; 32 | unsigned currentStationService:3; 33 | unsigned currentStationPresetNumber:4; 34 | }Status; 35 | }RemoteReceiverStatus; 36 | 37 | void SendRemoteReceiverStatus(RemoteReceiverStatus *remoteReceiverStatus); 38 | void SendRemoteReceiverStatusFixedData(void); 39 | 40 | 41 | #endif // REMOTE_RECIEVER_STATUS_H 42 | -------------------------------------------------------------------------------- /TMP10x_Drv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * TMP10x_Drv.c 3 | * 4 | * Created on: Jun 17, 2024 5 | * Author: karl.yamashita 6 | * 7 | * 8 | * The driver is the same for all of the TMP10x sensors. The only thing that changes is the configuration register. 9 | * In the TMP10x.h file, select the define for your TMP10x that you are using which will select the correct structure. 10 | * 11 | */ 12 | 13 | #include "main.h" 14 | 15 | 16 | int TMP10x_Read(I2C_GenericDef *i2c, uint16_t reg, void (*callback)(struct __I2C_GenericDef_ *i2c)) 17 | { 18 | int status = NO_ERROR; 19 | 20 | i2c->registerAddr[0] = reg; 21 | i2c->regSize = 1; 22 | i2c->RxISR = callback; 23 | 24 | status = I2C_Mem_Read_Generic_Method(i2c); 25 | if(status != NO_ERROR) 26 | { 27 | return status; 28 | } 29 | 30 | return status; 31 | } 32 | 33 | /* 34 | * Description: Be sure to initialize I2C data pointer with data and data size prior to calling this. 35 | */ 36 | int TMP10x_Write(I2C_GenericDef *i2c, uint16_t reg, void (*callback)(struct __I2C_GenericDef_ *i2c)) 37 | { 38 | int status = NO_ERROR; 39 | 40 | i2c->registerAddr[0] = reg; 41 | i2c->regSize = 1; 42 | i2c->TxISR = callback; 43 | 44 | status = I2C_Mem_Write_Generic_Method(i2c); 45 | if(status != NO_ERROR) 46 | { 47 | return status; 48 | } 49 | 50 | return status; 51 | } 52 | -------------------------------------------------------------------------------- /SystemTick_Handler_STM32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SystemTick_Handler_STM32.c 3 | * 4 | * Created on: Oct 6, 2025 5 | * Author: karl.yamashita 6 | * 7 | * Objective: 8 | * Instead of writing code in SysTick_Handler() in stm32xxxx_it.c, 9 | * you can add these SystemTick_Handler.c/h files to your project. 10 | * This will override the weak function, HAL_IncTick(); 11 | * 12 | * You can also register a callback to call after the uwTick variable is incremented. 13 | * 14 | * 15 | * Initialization step: Be sure to extern below variables, typically in main.h 16 | * extern __IO uint32_t uwTick; 17 | * extern SystemTick_t sysTick; 18 | */ 19 | 20 | #include "main.h" 21 | 22 | SystemTick_t sysTick = {0}; 23 | 24 | 25 | /* 26 | * Description: This overrides the weak function 27 | */ 28 | void HAL_IncTick(void) 29 | { 30 | uwTick += (uint32_t)uwTickFreq; 31 | 32 | if(sysTick.callback != NULL) 33 | { 34 | sysTick.callback(); 35 | } 36 | } 37 | 38 | /* 39 | * Description: Register a callback, typically before main while loop, that will get called from HAL_IncTick 40 | * 41 | * Example; 42 | * SystemTickCallbackRegister(&sysTick, TimerCallbackHandlerTick); 43 | */ 44 | void SystemTickCallbackRegister(SystemTick_t *sysTick, void *callback) 45 | { 46 | sysTick->callback = callback; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /NotifyUser.c: -------------------------------------------------------------------------------- 1 | 2 | #include "main.h" 3 | #include "NotifyUser.h" 4 | 5 | 6 | /* 7 | * This file also needs to include UartCharBuffer.h 8 | * 9 | * 10 | */ 11 | 12 | 13 | /* 14 | * Description: This will add CR and LF to string before saving to tx buffer. 15 | * Input: Pointer to buffer, the string to add to tx buffer, the size of string, and CR/LF (carriage return/linefeed enable) 16 | * 17 | */ 18 | void NotifyUser(UartBufferStruct *msg, char *str, uint32_t strlen, bool lineFeed) 19 | { 20 | uint8_t strMsg[UART_TX_DATA_SIZE] = {0}; 21 | uint32_t size = strlen; 22 | 23 | memcpy(&strMsg, str, size); 24 | 25 | if(lineFeed == true) 26 | { 27 | strcat((char*)strMsg, "\r\n"); 28 | size += 2; 29 | } 30 | 31 | UART_TX_AddDataToBuffer(msg, strMsg, size); 32 | } 33 | 34 | // need to include ErrorStatus.c/h 35 | void NotifyUser_Error(UartBufferStruct *msg, char *msgCpy, uint32_t error) 36 | { 37 | char str[64] = {0}; 38 | 39 | GetErrorString(error, str); // from ErrorStatus.c 40 | 41 | strcat(msgCpy, "="); 42 | strcat(msgCpy, str); 43 | 44 | NotifyUser(msg, msgCpy, strlen(msgCpy), true); 45 | } 46 | 47 | void NotifyUser_PrintReply(UartBufferStruct *msg, char *msgCpy, char *msg2) 48 | { 49 | strcat(msgCpy, "="); 50 | strcat(msgCpy, msg2); 51 | NotifyUser(msg, msgCpy, strlen(msgCpy), true); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Xilinx/UartOut.c: -------------------------------------------------------------------------------- 1 | /* 2 | * UartOut.c 3 | * 4 | * Created on: Jun 2, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #include "main.h" 9 | #include "UartOut.h" 10 | 11 | static void OutbyteUart1(char c); 12 | 13 | /* 14 | * Description: Transmit string array 15 | * 16 | * 17 | */ 18 | HAL_StatusTypeDef UartTxMessage(UartCharBufferTxStruct *uartBufferPointer){ 19 | uint8_t *pData = uartBufferPointer->data; 20 | while (*pData != '\0') { 21 | switch (uartBufferPointer->uartPort) { 22 | case UART_PORT_0: 23 | OutbyteUart1(*pData); 24 | break; 25 | case UART_PORT_1: 26 | OutbyteUart1(*pData); 27 | break; 28 | case UART_PORT_2: 29 | // n/a 30 | break; 31 | } 32 | pData++; 33 | } 34 | return HAL_OK; 35 | } 36 | 37 | /* 38 | * Description: transmit 39 | * 40 | * 41 | */ 42 | void PrintUart1(const char8 *ptr) 43 | { 44 | while (*ptr != (char8)0) { 45 | OutbyteUart1 (*ptr); 46 | ptr++; 47 | } 48 | } 49 | 50 | /* 51 | * Description: Prints string with carriage return and line feed. 52 | * 53 | * 54 | */ 55 | void PrintLine(const char8 *ptr){ 56 | print(ptr); 57 | print("\r\n"); 58 | } 59 | 60 | /* 61 | * Description: Transmit one byte at a time on Uart1 62 | * 63 | * Input: The 64 | * 65 | */ 66 | static void OutbyteUart1(char c) { 67 | XUartLite_SendByte(XPAR_AXI_UARTLITE_0_BASEADDR, c); 68 | } 69 | 70 | -------------------------------------------------------------------------------- /kickTheDog.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_KICK_THE_DOG 3 | // for use with STM32, for now. 4 | 5 | #include "main.h" 6 | #include "kickTheDog.h" 7 | #include "wwdg.h" 8 | 9 | /* 10 | Create a timer callback to call this funcion. 11 | 12 | TimeoutCalculation((hwwdg.Init.Counter - hwwdg.Init.Window) + 1) + 1 13 | 14 | hwwdg.Init.Prescaler = WWDG_PRESCALER_4; 15 | hwwdg.Init.Window = 127; 16 | hwwdg.Init.Counter = 127; 17 | hwwdg.Init.EWIMode = WWDG_EWI_DISABLE; 18 | 19 | */ 20 | void KickTheDog(void) { 21 | HAL_WWDG_Refresh(&hwwdg); 22 | } 23 | 24 | /** 25 | * @brief Timeout calculation function. 26 | * This function calculates any timeout related to 27 | * WWDG with given prescaler and system clock. 28 | * @param timevalue: period in term of WWDG counter cycle. 29 | * @retval None 30 | */ 31 | uint32_t TimeoutCalculation(uint32_t timevalue) 32 | { 33 | uint32_t timeoutvalue = 0; 34 | uint32_t pclk1 = 0; 35 | uint32_t wdgtb = 0; 36 | 37 | /* considering APB divider is still 1, use HCLK value */ 38 | pclk1 = HAL_RCC_GetPCLK1Freq(); 39 | 40 | /* get prescaler */ 41 | wdgtb = (1 << ((hwwdg.Init.Prescaler) >> 7)); /* 2^WDGTB[1:0] */ 42 | 43 | /* calculate timeout */ 44 | timeoutvalue = ((4096 * wdgtb * timevalue) / (pclk1 / 1000)); 45 | 46 | return timeoutvalue; 47 | } 48 | 49 | 50 | #endif // USE_KICK_THE_DOG 51 | -------------------------------------------------------------------------------- /I2C_Drv_TM4C.h: -------------------------------------------------------------------------------- 1 | /* 2 | * i2c_hal.h 3 | * 4 | * Created on: Mar 5, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef I2C_HAL_H_ 9 | #define I2C_HAL_H_ 10 | 11 | #include "main.h" 12 | 13 | // I2C defines 14 | #ifndef _I2C_BUFFER_DEFINES 15 | #define _I2C_BUFFER_DEFINES 16 | #define MAX_I2C_DATA_BUFFER 2// 2 bytes, register and data byte 17 | #define MAX_I2C_MESSAGE_BUFFER 2 18 | #endif 19 | 20 | 21 | #define I2C_TIMEOUT 125 22 | 23 | // polling 24 | int I2C_Master_Receive(uint32_t i2c_base, uint16_t DevAddress, uint8_t *pData, uint32_t size, uint32_t timeout); 25 | int I2C_Master_Transmit(uint32_t i2c_base, uint16_t DevAddress, uint8_t *pData, uint32_t size, uint32_t timeout); 26 | int I2C_Master_Mem_Read(uint32_t i2c_base, uint16_t DevAddress, uint16_t regAddress, uint32_t regSize, uint8_t *pData_OUT, uint32_t size, uint32_t timeout); 27 | int I2C_Master_Mem_Write(uint32_t i2c_base, uint16_t DevAddress, uint16_t regAddress, uint32_t regSize, uint8_t *pData_OUT, uint32_t readSize, uint32_t timeout); 28 | // interrupt 29 | int I2C_Master_Mem_Read_Generic_IT(uint32_t i2c_base, uint16_t DevAddress, uint16_t regAddress, uint32_t regSize, uint8_t *pData_OUT, uint32_t readSize); 30 | int I2C_Master_Mem_Write_Generic_IT(uint32_t i2c_base, uint16_t DevAddress, uint16_t regAddress, uint32_t regSize, uint8_t *pData, uint32_t writeSize); 31 | 32 | #endif /* I2C_HAL_H_ */ 33 | -------------------------------------------------------------------------------- /Vehicle Drivers/ChimeCommand.h: -------------------------------------------------------------------------------- 1 | #ifndef CHIME_COMMAND_H 2 | #define CHIME_COMMAND_H 3 | 4 | typedef union ChimeCommand{ 5 | struct{ 6 | uint8_t byte4; 7 | uint8_t byte3; 8 | uint8_t byte2; 9 | uint8_t byte1; 10 | uint8_t byte0; 11 | }Bytes; 12 | struct{ 13 | uint8_t sC_SndPriority; 14 | uint8_t sC_SndDutCyc; 15 | uint8_t sC_NmofRp; 16 | uint8_t sC_SndCdnPrd; 17 | unsigned sC_SndTne:4; 18 | unsigned rightRear:1; 19 | unsigned leftRear:1; 20 | unsigned passengerFront:1; 21 | unsigned driverFront:1; 22 | }Chime; 23 | }ChimeCommand; 24 | #define chimeArrayChime ChimeCommand.chimeArray 25 | #define sC_SoundToneChime ChimeCommand.Chime.sC_SndTone 26 | #define rightRearChime ChimeCommand.Chime.rightRear 27 | #define leftRearChime ChimeCommand.Chime.leftRear 28 | #define passengerFrontChime ChimeCommand.Chime.passengerFront 29 | #define driverFrontChime ChimeCommand.Chime.driverFront 30 | #define sC_TimeChime ChimeCommand.Chime.sC_SndCdnPrd 31 | #define sC_NumberOfRepetitionChime ChimeCommand.Chime.sC_NmofRp 32 | #define sC_DutyCycleChime ChimeCommand.Chime.sC_SndDutCyc 33 | #define sC_PriorityChime ChimeCommand.Chime.sC_SndPriority 34 | 35 | 36 | 37 | void ServiceChimeCommand(uint8_t *data); 38 | void SendChimeCommand(ChimeCommand *chimeCommand); 39 | void SendChimeCommandPreset(uint8_t type, uint8_t repetition); 40 | 41 | 42 | 43 | 44 | #endif // CHIME_COMMAND_H 45 | -------------------------------------------------------------------------------- /UART_Handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * UART_Handler.h 3 | * 4 | * Created on: Jul 21, 2023 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_UART_HANDLER_H_ 9 | #define INC_UART_HANDLER_H_ 10 | 11 | 12 | #ifdef HAL_MODULE_ENABLED // STM32 13 | 14 | void UART_EnableRxInterrupt(UartBufferStruct *msg); 15 | void UART_CheckRxIntError(UartBufferStruct *msg); 16 | void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart); 17 | int UART_TxMessage_IT(UartBufferStruct *msg); 18 | 19 | #endif 20 | 21 | #ifdef ccs 22 | 23 | enum 24 | { 25 | UART_TX_DONE, 26 | UART_TX_PENDING 27 | }; 28 | 29 | void USART0_IRQHandler(void); 30 | int UART_TxMessage_IT(UartBufferStruct *msg); 31 | 32 | int UART_Parse(UartBufferStruct *msg); 33 | int UART_TxMessage(UartBufferStruct *msg); 34 | #endif 35 | 36 | #ifdef _XC_H // Microchip 37 | 38 | // PORT number defines to assign to instance. 39 | enum 40 | { 41 | UART_PORT_0, 42 | UART_PORT_1, 43 | UART_PORT_2, 44 | UART_PORT_3, 45 | UART_PORT_4, 46 | UART_PORT_5, 47 | UART_PORT_6, 48 | UART_PORT_7, 49 | UART_PORT_8, 50 | UART_PORT_9, 51 | UART_PORT_10, 52 | UART_PORT_11, 53 | UART_PORT_12, 54 | UART_PORT_13, 55 | UART_PORT_14, 56 | UART_PORT_15 57 | // add more if needed. 58 | }; 59 | 60 | void UART1_Receive_CallBack(void); 61 | void UART2_Receive_CallBack(void); 62 | int UART_TxMessage_IT(UartTxBufferStruct *msg); 63 | 64 | 65 | #endif 66 | 67 | #endif /* INC_UART_HANDLER_H_ */ 68 | -------------------------------------------------------------------------------- /Flash_ReadWrite_Drv_STM32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Flash_ReadWrite_Drv_STM32.h 3 | * 4 | * Created on: Oct 10, 2024 5 | * Author: codek 6 | */ 7 | 8 | #ifndef INC_FLASH_READWRITE_DRV_STM32_H_ 9 | #define INC_FLASH_READWRITE_DRV_STM32_H_ 10 | 11 | 12 | #define BOOTLOADER_FLAG_ADDRESS 0x8007800 13 | #define FLASH_EEPROM_START_ADDRESS 0x8007000 14 | 15 | // SerialPartNumber_t 16 | #define FLASH_DOUBLE_WORD_SIZE 8 // the mount of FLASH_Data_t created in FLASH_DataStruct_t 17 | #define FLASH_STRING_DATA_SIZE 48 // max amount of characters for each FLASH_Data_t 18 | #define FLASH_SIZEOF_DATA_STRUCT (FLASH_DOUBLE_WORD_SIZE * FLASH_STRING_DATA_SIZE) 19 | #define FLASH_WRITE_DOUBLE_WORD_SIZE (FLASH_SIZEOF_DATA_STRUCT / FLASH_DOUBLE_WORD_SIZE) 20 | 21 | 22 | typedef struct 23 | { 24 | FLASH_EraseInitTypeDef flashEraseInit; 25 | uint32_t address; 26 | uint8_t *data; // increment of 8 bytes 27 | uint32_t doubleWordAmount; 28 | uint32_t PageError; 29 | }__attribute__ ((aligned (32))) FlashWriteInit_t; 30 | 31 | typedef struct 32 | { 33 | uint32_t address; 34 | uint8_t *data; // pointer to array buffer 35 | uint32_t count; // number of bytes to read 36 | }__attribute__ ((aligned (32))) FlashReadInit_t; 37 | 38 | 39 | int FLASH_WriteDoubleWord(FlashWriteInit_t *flashInit); 40 | 41 | uint8_t FLASH_DATA_Read(uint32_t address); 42 | int FLASH_DATA_ReadMultiBytes(FlashReadInit_t *flash); 43 | 44 | #endif /* INC_FLASH_READWRITE_DRV_STM32_H_ */ 45 | -------------------------------------------------------------------------------- /Vehicle Drivers/AudioAmplifierStatus.h: -------------------------------------------------------------------------------- 1 | #ifndef AUDIO_AMPLFIER_H 2 | #define AUDIO_AMPLFIER_H 3 | 4 | #include "main.h" 5 | 6 | #if defined GMLAN_V1 7 | 8 | typedef union AudioAmplifierStatus{ 9 | struct { 10 | uint8_t audioAmplifierStatusByte; 11 | }Byte; 12 | struct { 13 | unsigned dspPresentBit:1; 14 | unsigned surroundSoundSystemPresentBit:1; 15 | unsigned noiseCompressionPresentBit:1; 16 | unsigned virtualDevicePresentBit:1; 17 | unsigned :1; 18 | unsigned :1; 19 | unsigned :1; 20 | unsigned :1; 21 | } AmplifierControlBits; 22 | }AudioAmplifierStatus; 23 | 24 | 25 | 26 | void ServiceAudioAmplifier(uint8_t *data); 27 | void SendAmplifierControl(uint8_t targetSink, uint8_t connectCommand, \ 28 | uint8_t channelType, uint8_t contentType ); 29 | void SendAmplifierSetting(uint8_t targetSink, uint8_t settingType,\ 30 | uint8_t settingData, uint8_t settingTime); 31 | void SendAmplifierMute(uint8_t targetSink, uint8_t amplifierMute, uint8_t settingTime); 32 | void SendAmplifierStatus(void); 33 | void ServiceAmplifierData(void); 34 | uint8_t GetSurroundSoundSystemPresentBit(void); 35 | uint8_t GetAmplifierPresentFlag(void); 36 | 37 | #endif // GMLAN_V1 38 | 39 | #if defined CHRYSLER_V2 40 | void ServiceAudioAmplifierStatus(uint8_t *data); 41 | uint8_t GetAmplifierPresentFlag(void); 42 | void EmulateChryslerAmplifier(void); 43 | #endif // CHRYSLER_V2 44 | 45 | 46 | #endif // AUDIO_AMPLFIER_H 47 | -------------------------------------------------------------------------------- /I2C_Generic_Handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: I2C_Generic_Handler.h 3 | * Author: karl.yamashita 4 | * 5 | * Created on August 12, 2022, 12:30 PM 6 | */ 7 | 8 | #ifndef I2C_GENERIC_HANDLER_H 9 | #define I2C_GENERIC_HANDLER_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #ifdef _XC_H 16 | #define SLAVE_I2C_GENERIC_SLAVE_TIMEOUT 100 17 | #define SLAVE_I2C_GENERIC_RETRY_MAX 3 18 | #endif 19 | 20 | 21 | #define I2C_BAUD_100_KHZ 0x1C0 // 100 kHz 22 | #define I2C_BAUD_400_KHZ 0x6F // 400 kHz 23 | 24 | 25 | int I2C_Master_Receive_Generic(uint32_t i2c_base, uint8_t slaveAddress, uint8_t *data, uint8_t readSize); 26 | int I2C_Master_Transmit_Generic(uint32_t i2c_base, uint8_t slaveAddress, uint8_t *data, uint8_t writeSize); 27 | int I2C_Master_Read_Register_Generic(uint32_t i2c_base, uint8_t slaveAddress, uint8_t *regAddress, uint8_t *data_OUT, uint8_t readSize); 28 | int I2C_Master_Write_Register_Generic(uint32_t i2c_base, uint8_t slaveAddress, uint8_t *regAddress, uint8_t *data_IN, uint8_t writeSize); 29 | int I2C_Master_Page_Plus_Read_Register_Generic(uint32_t i2c_base, uint8_t slaveAddress, uint8_t page, uint8_t *regAddress, uint8_t *data_OUT, uint8_t readSize); 30 | int I2C_Master_Page_Plus_Write_Register_Generic(uint32_t i2c_base, uint8_t slaveAddress, uint8_t page, uint8_t *regAddress, uint8_t *data_OUT, uint8_t readSize); 31 | 32 | 33 | int I2C_ChangeBaudRate(uint32_t i2c_base, uint16_t baudRate); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /* I2C_GENERIC_HANDLER_H */ 40 | 41 | -------------------------------------------------------------------------------- /Vehicle Drivers/InfotainmentAllowed.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "InfotainmentAllowed.h" 3 | #include "GMLAN_Defines.h" 4 | #include "GMLAN_CAN_ID.h" 5 | #include "CAN.h" 6 | #include "CAN_Buffer.h" 7 | #include "mTimers.h" 8 | #include "Sleep.h" 9 | 10 | 11 | uint8_t infotainmentAllowedStatus; // when looking for status, else we're emulating radio so we would be sending status. 12 | 13 | // gateway: typically this is called if we're a gateway receiving from radio 14 | void ServiceInfotainmentAllowed(unsigned char *data) { 15 | infotainmentAllowedStatus = data[0] & 0x01; 16 | } 17 | 18 | bool GetInfotainmentAllowedStatus(void) { 19 | return infotainmentAllowedStatus; 20 | } 21 | // end gateway 22 | 23 | 24 | // radio: 25 | // typically this is called if interface is replacing headunit 26 | void SendInfotainmentAllowedCallbackCAN2(int status) { 27 | CanTxMsgTypeDef canMessage; 28 | canMessage.ExtId = INFOTAINMENT_ALLOWED_ID; // Set extended ID for transmit message 29 | canMessage.IDE = CAN_ID_EXT; 30 | canMessage.RTR = CAN_RTR_DATA; 31 | canMessage.DLC = 1; 32 | canMessage.Data[0] = status; 33 | AddTxBuffer2(&canMessage); 34 | } 35 | 36 | // call this when PowerMode is on or about to go to sleep 37 | bool sentInfotainmentAllowed = false; 38 | void SendInfotainmentAllowed(bool flag) { 39 | if(sentInfotainmentAllowed == true) { 40 | sentInfotainmentAllowed = false; 41 | SendInfotainmentAllowedCallbackCAN2(flag); 42 | } else { 43 | sentInfotainmentAllowed = true; 44 | SendInfotainmentAllowedCallbackCAN2(flag); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /GPIO_Ports.h: -------------------------------------------------------------------------------- 1 | #ifndef GPIO_PORTS_H 2 | #define GPIO_PORTS_H 3 | #include "main.h" 4 | 5 | #define GPIO_DIRECTION_INPUT 1 6 | #define GPIO_DIRECTION_OUTPUT 0 7 | 8 | // Port A 9 | int8_t PortA_On (uint32_t pin); 10 | 11 | int8_t PortA_Off (uint32_t pin); 12 | 13 | int8_t PortA_Toggle (uint32_t pin); 14 | 15 | // port B 16 | int8_t PortB_On (uint32_t pin); 17 | 18 | int8_t PortB_Off (uint32_t pin); 19 | 20 | int8_t PortB_Toggle (uint32_t pin); 21 | 22 | // port C 23 | int8_t PortC_On (uint32_t pin); 24 | 25 | int8_t PortC_Off (uint32_t pin); 26 | 27 | int8_t PortC_Toggle (uint32_t pin); 28 | 29 | #if defined(__STM32F1xx_HAL_CAN_H) 30 | // port D 31 | int8_t PortD_On (uint32_t pin); 32 | 33 | int8_t PortD_Off (uint32_t pin); 34 | 35 | int8_t PortD_Toggle (uint32_t pin); 36 | #endif // __STM32F1xx_HAL_CAN_H 37 | 38 | #ifdef STM32F407xx 39 | // port D 40 | int8_t PortD_On (uint32_t pin); 41 | 42 | int8_t PortD_Off (uint32_t pin); 43 | 44 | int8_t PortD_Toggle (uint32_t pin); 45 | 46 | // Port E 47 | int8_t PortE_On (uint32_t pin); 48 | 49 | int8_t PortE_Off (uint32_t pin); 50 | 51 | int8_t PortE_Toggle (uint32_t pin); 52 | #endif // STM32F407xx 53 | 54 | 55 | // read pins 56 | 57 | int8_t ReadPortA(uint16_t pin); 58 | 59 | int8_t ReadPortB(uint16_t pin); 60 | 61 | int8_t ReadPortC(uint16_t pin); 62 | 63 | #ifdef STM32F407xx 64 | int8_t ReadPortD(uint16_t pin); 65 | 66 | int8_t ReadPortE(uint16_t pin); 67 | #endif 68 | 69 | #ifdef __STM32F1xx_HAL_CAN_H 70 | int8_t ReadPortD(uint16_t pin); 71 | #endif 72 | 73 | #endif // GPIO_PORTS_H 74 | 75 | -------------------------------------------------------------------------------- /Xilinx/Peripherals_Init.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Peripherals_Init.c 3 | * 4 | * Created on: May 26, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | 9 | #include "main.h" 10 | #include "Peripherals_Init.h" 11 | 12 | #define PeripheralsInit_PrintLine 13 | 14 | /* 15 | * Description: Initiates peripherals 16 | * Input: none 17 | * Output: the number of errors counted 18 | */ 19 | int Peripherals_Init(void){ 20 | int status; 21 | int errorCount = 0; 22 | status = Init_InterruptController(); 23 | if (status != XST_SUCCESS) { 24 | errorCount += 1; 25 | #ifdef PeripheralsInit_PrintLine 26 | PrintLine("CMD01:1"); 27 | #endif 28 | } 29 | 30 | status = Init_Timer(); 31 | if (status != XST_SUCCESS) { 32 | #ifdef PeripheralsInit_PrintLine 33 | PrintLine("CMD01:2"); 34 | #endif 35 | } 36 | 37 | status = Init_Uart0(); 38 | if (status != XST_SUCCESS) { 39 | errorCount += 1; 40 | #ifdef PeripheralsInit_PrintLine 41 | PrintLine("CMD01:3"); 42 | #endif 43 | } 44 | 45 | status = I2C_Init(); 46 | if (status != XST_SUCCESS) { 47 | errorCount += 1; 48 | #ifdef PeripheralsInit_PrintLine 49 | PrintLine("CMD01:4"); 50 | #endif 51 | } 52 | 53 | status = SPI_Init(); 54 | if (status != XST_SUCCESS) { 55 | errorCount += 1; 56 | #ifdef PeripheralsInit_PrintLine 57 | PrintLine("CMD01:5"); 58 | #endif 59 | } 60 | 61 | status = Init_GPIO(); 62 | if (status != XST_SUCCESS) { 63 | errorCount += 1; 64 | #ifdef PeripheralsInit_PrintLine 65 | PrintLine("CMD01:6"); 66 | #endif 67 | } 68 | 69 | return errorCount; 70 | } 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /TI/Timer_Config.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Timer_Config.c 3 | * 4 | * Created on: Jul 18, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | 9 | #include "main.h" 10 | 11 | /* 12 | * Description: One-Shot or Periodic mode 13 | * 14 | * example; 15 | * 16 | * TimerConfigDef timer0_Config = {0}; // create new variable 17 | * 18 | * timer0_Config.timerBase = TIMER0_BASE; 19 | timer0_Config.loadCount = ((SysCtlClockGet()/25000) - 1); 20 | timer0_Config.config = TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC; 21 | timer0_Config.controlTrigger = true; 22 | timer0_Config.timerParam = TIMER_A; 23 | 24 | Timer_Config(&timer0_Config); 25 | */ 26 | void Timer_Config(TimerConfigDef *config) 27 | { 28 | // enable timer 29 | SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); 30 | while(!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0)); 31 | 32 | TimerConfigure(config->timerBase, config->config); 33 | 34 | // Set ADC sampling frequency to be 25KHz i.e. every 40uS. 35 | TimerLoadSet(config->timerBase, config->timerParam, config->loadCount); 36 | 37 | // Enable the ADC trigger output for Timer A. 38 | TimerControlTrigger(config->timerBase, config->timerParam, config->controlTrigger); 39 | 40 | TimerIntRegister(config->timerBase, config->timerParam, Timer0_IRQHandler); 41 | 42 | IntEnable(INT_TIMER0A); 43 | 44 | TimerIntEnable(config->timerBase, TIMER_TIMA_TIMEOUT); 45 | 46 | IntMasterEnable(); 47 | 48 | // Enable Timer 0 which will start the whole application process. 49 | TimerEnable(config->timerBase, config->timerParam); 50 | } 51 | -------------------------------------------------------------------------------- /USB_CDC_Buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | * @attention 4 | * 5 | * Copyright (c) 2025 Karl Yamashita 6 | * All rights reserved. 7 | * 8 | * This software is licensed under terms that can be found in the LICENSE file 9 | * in the root directory of this software component. 10 | * If no LICENSE file comes with this software, it is provided AS-IS. 11 | * 12 | ****************************************************************************** 13 | */ 14 | 15 | #ifndef USB_CDC_BUFFER_H 16 | #define USB_CDC_BUFFER_H 17 | 18 | 19 | 20 | 21 | #define ID_AND_SIZE_LENGTH 4 // (uint16_t id) (uint16_t size) 22 | #define USB_DATA_SIZE (256 - ID_AND_SIZE_LENGTH) //256 - id - size 23 | 24 | typedef union 25 | { 26 | struct 27 | { 28 | uint8_t data[USB_DATA_SIZE + ID_AND_SIZE_LENGTH]; 29 | }Byte; 30 | struct 31 | { 32 | uint32_t id:8; 33 | uint32_t :16; // reserved 34 | uint32_t size:8; 35 | uint8_t data[USB_DATA_SIZE]; 36 | }Status; 37 | }USB_Data_t; 38 | 39 | typedef struct 40 | { 41 | // rx 42 | USB_Data_t *rxQueue; 43 | USB_Data_t *msgToParse; 44 | uint32_t rxQueueSize; 45 | RING_BUFF_STRUCT rxPtr; 46 | // tx 47 | USB_Data_t *txQueue; 48 | uint32_t txQueueSize; 49 | RING_BUFF_STRUCT txPtr; 50 | }USB_MsgStruct; 51 | 52 | 53 | 54 | int USB_SendMessage(USB_MsgStruct *msg); 55 | void USB_AddTxBuffer(USB_MsgStruct *msg, USB_Data_t *data); 56 | void USB_AddRxBuffer(USB_MsgStruct *msg, uint8_t *data, uint32_t size); 57 | uint8_t USB_DataAvailable(USB_MsgStruct *msg); 58 | 59 | #endif // USB_CDC_BUFFER_H 60 | -------------------------------------------------------------------------------- /Xilinx/InterruptHandlers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * InterruptHandlers.h 3 | * 4 | * Created on: Jun 2, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SRC_INTERRUPTHANDLERS_H_ 9 | #define SRC_INTERRUPTHANDLERS_H_ 10 | 11 | 12 | #define HAL_MAX_DELAY 0xFFFFFFFFU 13 | 14 | typedef enum 15 | { 16 | HAL_TICK_FREQ_10HZ = 100U, 17 | HAL_TICK_FREQ_100HZ = 10U, 18 | HAL_TICK_FREQ_1KHZ = 1U, 19 | HAL_TICK_FREQ_DEFAULT = HAL_TICK_FREQ_1KHZ 20 | } HAL_TickFreqTypeDef; 21 | 22 | /* 23 | * The following structure contains fields that are used with the callbacks 24 | * (handlers) of the IIC driver. The driver asynchronously calls handlers 25 | * when abnormal events occur or when data has been sent or received. This 26 | * structure must be volatile to work when the code is optimized. 27 | */ 28 | volatile typedef struct { 29 | int EventStatus; 30 | int RemainingRecvBytes; 31 | int EventStatusUpdated; 32 | int RecvBytesUpdated; 33 | int ReceiveComplete; 34 | int TransmitComplete; 35 | } HandlerInfo; 36 | 37 | extern uint32_t uwTick; 38 | extern HAL_TickFreqTypeDef uwTickFreq; 39 | 40 | void SysTick_Handler(void* ref); 41 | void HAL_IncTick(void); 42 | uint32_t HAL_GetTick(void); 43 | void HAL_Delay(uint32_t Delay); 44 | 45 | void GPIO_Interrupt0(void *ref); 46 | void Uart0ReceiveInterruptHandler(void *CallBackRef, unsigned int EventData); 47 | void I2CSendHandler(XIic *InstancePtr); 48 | void I2CRecvHandler(void *CallbackRef, int ByteCount); 49 | void I2CStatusHandler(void *CallbackRef, int Status); 50 | 51 | 52 | #endif /* SRC_INTERRUPTHANDLERS_H_ */ 53 | -------------------------------------------------------------------------------- /Vehicle Drivers/CAN_BufferV2.h: -------------------------------------------------------------------------------- 1 | #ifndef CAN_BUFFER_V2_H 2 | #define CAN_BUFFER_V2_H 3 | 4 | #include "RingBuff.h" 5 | 6 | // typically this will be 8 7 | #define CAN_RX_BUFF_SIZE 8 8 | #define CAN_TX_BUFF_SIZE 8 9 | 10 | // increase if buffer over run. 11 | #define CAN_RX_QUEUE_SIZE 4 12 | #define CAN_TX_QUEUE_SIZE 4 13 | 14 | 15 | // Receive 16 | typedef struct 17 | { 18 | struct 19 | { 20 | CAN_RxHeaderTypeDef header; 21 | uint8_t data[CAN_RX_BUFF_SIZE]; 22 | }QUEUE[CAN_RX_QUEUE_SIZE]; 23 | 24 | RING_BUFF_INFO ptr; 25 | }CanRxMsg_Struct; 26 | 27 | // Transmit 28 | typedef struct 29 | { 30 | struct 31 | { 32 | CAN_TxHeaderTypeDef header; 33 | uint8_t data[CAN_TX_BUFF_SIZE]; 34 | }QUEUE[CAN_TX_QUEUE_SIZE]; 35 | 36 | RING_BUFF_INFO ptr; 37 | }CanTxMsg_Struct; 38 | 39 | // temporary rxMsg buffer without queue buffer 40 | typedef struct 41 | { 42 | CAN_RxHeaderTypeDef header; 43 | uint8_t data[CAN_RX_BUFF_SIZE]; 44 | }CanRxMsgTemp_Struct; 45 | 46 | // temporary txMsg buffer without queue buffer 47 | typedef struct 48 | { 49 | CAN_TxHeaderTypeDef header; 50 | uint8_t data[CAN_TX_BUFF_SIZE]; 51 | }CanTxMsgTemp_Struct; 52 | 53 | 54 | void CAN_SendTxMessage(CAN_HandleTypeDef *hcan, CanTxMsg_Struct *canMsg); 55 | void CAN_AddTxBuffer(CanTxMsg_Struct *canMsg_Out, CanTxMsgTemp_Struct *canMsg); 56 | void AddCanRxBuffer(CanRxMsg_Struct *canMsg_Out, CanRxMsg_Struct *canMsg); 57 | void CAN_GetMessage(CAN_HandleTypeDef *hcan, CanRxMsg_Struct *rxMsg); 58 | int CAN_MsgAvailable(CanRxMsg_Struct *rxMsg, CanTxMsgTemp_Struct *canMsg); 59 | 60 | 61 | 62 | #endif // CAN_BUFFER_V2_H 63 | -------------------------------------------------------------------------------- /Vehicle Drivers/CHRYSLER_Defines.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_CHRYSLER_DEFINES 3 | #ifndef CHRYSLER_DEFINES_H 4 | #define CHRYSLER_DEFINES_H 5 | 6 | // Steering Wheel Controls 7 | #define SWC_BUTTON_RELEASE 0x00 8 | #define SWC_LEFT_UP 0x10 9 | #define SWC_LEFT_DOWN 0x20 10 | #define SWC_LEFT_MIDDLE 0x40 11 | #define SWC_RIGHT_UP 0x04 12 | #define SWC_RIGHT_DOWN 0x08 13 | #define SWC_RIGHT_MIDDLE 0x01 14 | 15 | //Power Mode 16 | #if defined CHRYSLER_V5 // need to check if this is for CRYSLER_V4 or V3 17 | #define POWER_MODE_OFF 0x00 18 | #define POWER_MODE_ACCESSORY 0x03 19 | #define POWER_MODE_IGNITION 0x04 20 | #define POWER_MODE_CRANK 0x15 21 | #define POWER_MODE_MASK 0x1F 22 | #elif defined CHRYSLER_V3 23 | #define POWER_MODE_OFF 0x00 24 | #define POWER_MODE_ACCESSORY 0x03 25 | #define POWER_MODE_IGNITION 0x04 26 | #define POWER_MODE_CRANK 0x05 27 | #define POWER_MODE_MASK 0x03 28 | 29 | 30 | //Power Mode LSFTCAN 31 | #elif defined CHRYSLER_V2 32 | #define POWER_MODE_OFF 0x00 33 | #define POWER_MODE_ACCESSORY 0x03 34 | #define POWER_MODE_IGNITION 0x04 35 | #define POWER_MODE_CRANK 0x05 36 | #define POWER_MODE_MASK 0x03 37 | #else 38 | #warning "need to define which powerMode mask to use" 39 | #endif // USE_LSFTCAN_POWERMODE 40 | 41 | // Gear Information 42 | #define GEAR_PARK 0x0D 43 | #define GEAR_REVERSE 0x0B 44 | #define GEAR_NUETRAL 0x00 45 | #define GEAR_DRIVE 0x01 46 | 47 | // 74HCT4052 or FSAV331 switches 48 | #define NO_VIDEO 0xFF 49 | #define REAR_VIDEO 0 50 | #define FRONT_VIDEO 1 51 | #define LEFT_VIDEO 2 52 | #define RIGHT_VIDEO 3 53 | 54 | #endif // CHRYSLER_DEFINES_H 55 | #endif // USE_CHRYSLER_DEFINES 56 | -------------------------------------------------------------------------------- /I2C_ISR_Callback_STM32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * I2C_ISR_Callback_STM32.c 3 | * 4 | * Created on: Aug 8, 2024 5 | * Author: karl.yamashita 6 | * 7 | * 8 | * User can test for which I2C handle caused interrupt and call the ISR routine 9 | * 10 | */ 11 | 12 | 13 | 14 | #include "main.h" 15 | 16 | 17 | // Add extern for each I2C device instance 18 | extern I2C_GenericDef tmp102_data_1; 19 | 20 | 21 | 22 | /* 23 | * Description: Callback after memory/register has been Read. 24 | */ 25 | void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c) 26 | { 27 | if(hi2c == tmp102_data_1.i2c_instance) 28 | { 29 | if(tmp102_data_1.RxISR) 30 | { 31 | tmp102_data_1.RxISR(&tmp102_data_1); 32 | } 33 | } 34 | } 35 | 36 | /* 37 | * Description: Callback after memory/register has been written. 38 | */ 39 | void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c) 40 | { 41 | if(hi2c == tmp102_data_1.i2c_instance) 42 | { 43 | if(tmp102_data_1.TxISR) 44 | { 45 | tmp102_data_1.TxISR(&tmp102_data_1); 46 | } 47 | } 48 | } 49 | 50 | /* 51 | * Description: Callback after Read. 52 | */ 53 | void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c) 54 | { 55 | if(hi2c == tmp102_data_1.i2c_instance) 56 | { 57 | if(tmp102_data_1.RxISR) 58 | { 59 | tmp102_data_1.RxISR(&tmp102_data_1); 60 | } 61 | } 62 | } 63 | 64 | /* 65 | * Description: Callback after Write. 66 | */ 67 | void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c) 68 | { 69 | if(hi2c == tmp102_data_1.i2c_instance) 70 | { 71 | if(tmp102_data_1.TxISR) 72 | { 73 | tmp102_data_1.TxISR(&tmp102_data_1); 74 | } 75 | } 76 | } 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /Vehicle Drivers/Lighting.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_LIGHTING 3 | 4 | #include "main.h" 5 | #include "lighting.h" 6 | #include "can.h" 7 | #include "gpio.h" 8 | 9 | #if defined GMLAN_V1 10 | 11 | LightingStatus lightingStatus; 12 | #define lightingStatusByte0 lightingStatus.Bytes.byte0 13 | #define lightingStatusByte1 lightingStatus.Bytes.byte1 14 | #define leftTurnSignalActive lightingStatus.Status.leftTurnSignalActive 15 | #define rightTurnSignalActive lightingStatus.Status.rightTurnSignalActive 16 | #define parkingLightActive lightingStatus.Status.parkingLightsActive 17 | #define highBeamActive lightingStatus.Status.highBeamActive 18 | 19 | // lighting 20 | void ServiceLightingStatus(unsigned char *data) { 21 | lightingStatusByte0 = data[0]; // byte 0 22 | lightingStatusByte1 = data[1]; // byte 1 23 | } 24 | 25 | 26 | LightingStatus GetLightingStatus(void) { 27 | return lightingStatus; 28 | } 29 | 30 | 31 | // end lighting 32 | 33 | 34 | #endif // GMLAN_V1 35 | 36 | #if defined FORD 37 | uint8_t dimmerValue; 38 | 39 | void ServiceDimmer(uint8_t *data) { 40 | dimmerValue = data[0]; // first byte is int dimming level 41 | } 42 | 43 | uint8_t GetDimmerValue(void) { 44 | return dimmerValue; 45 | } 46 | 47 | 48 | #endif // FORD 49 | 50 | #if defined CHRYSLER_LSFTCAN 51 | 52 | 53 | 54 | #endif // CHRYSLER_LSFTCAN 55 | 56 | #if defined CHRYSLER_V3 57 | 58 | bool lightingStatus; 59 | 60 | void ServiceLightingStatus(unsigned char *data) { 61 | lightingStatus = data[0] >> 7; 62 | } 63 | 64 | 65 | bool GetLightingStatus(void) { 66 | return lightingStatus; 67 | } 68 | 69 | #endif // MSCAN 70 | #endif // USE_LIGHTING 71 | 72 | 73 | -------------------------------------------------------------------------------- /CommandList_Drv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CommandList_Array.h 3 | * 4 | * Created on: Apr 30, 2025 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_COMMANDLIST_DRV_H_ 9 | #define INC_COMMANDLIST_DRV_H_ 10 | 11 | 12 | #define COMMAND_DATA_SIZE 512 13 | #define COMMAND_NAME_MAX_SIZE 48 14 | 15 | 16 | 17 | #define DECLARE_CMD(name, min, max, flags, func, desc, syntax) \ 18 | { name, func, min, max, flags, desc, syntax } 19 | 20 | 21 | // String buffer and size. This is used to build the message to be sent to the user 22 | typedef struct 23 | { 24 | uint8_t data[COMMAND_DATA_SIZE]; 25 | uint32_t size; 26 | }CommandData_t; 27 | 28 | typedef int (*Function)(char *msg, char *retStr); // the function called should be able to parse get/set commands. 29 | 30 | typedef struct// __Command_t 31 | { 32 | const char * cmd; /* command name user types, ie. GO */ 33 | Function func; /* actual function to call */ 34 | int min_args; /* min num of args command accepts */ 35 | int max_args; /* max num of args command accepts */ 36 | int flags; /* command flags (e.g. repeat) */ 37 | const char * description; /* brief description of command */ 38 | const void * syntax; /* syntax of command */ 39 | }Command_t; 40 | 41 | 42 | #define CMD_HELP DECLARE_CMD("help", 0, 0, 0, Command_List_Print, "show available commands", "help?") 43 | 44 | 45 | void Command_List_Poll(void); 46 | int Command_List_Print(char *msg, char *retStr); 47 | int Command_List_Parse(char *msg, char *retStr); 48 | 49 | #endif /* INC_COMMANDLIST_DRV_H_ */ 50 | -------------------------------------------------------------------------------- /Vehicle Drivers/ArbTextReqSetDispParameter.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef ARB_TEXT_REQ_SET_DISP_PARAMETER_H 3 | #define ARB_TEXT_REQ_SET_DISP_PARAMETER_H 4 | 5 | /* 6 | typedef struct ArbTextReqSetDispParameters{ 7 | unsigned horizontalJustify:2; 8 | unsigned font:2; 9 | unsigned characterSet:2; 10 | unsigned char requesterCaretDisplayLineIdentifier; 11 | unsigned char sessionFunctionCode; 12 | unsigned requesterSessionIdentifier:3; 13 | unsigned targetDisplayDeviceSessioMode:4; 14 | unsigned targetDisplayDeviceIdentifier:4; 15 | unsigned requestingDeviceIdentifier:3; 16 | unsigned :4; // 4 bits not used 17 | unsigned :8; // byte 0 is not used 18 | }ArbTextReqSetDispParameters; 19 | */ 20 | 21 | typedef union 22 | { 23 | struct 24 | { 25 | uint8_t data[5]; 26 | }Bytes; 27 | struct 28 | { 29 | unsigned targetDisplayDeviceIdentifier:4; 30 | unsigned requestingDeviceIdentifier:3; 31 | unsigned :1; 32 | 33 | unsigned requesterSessionIdentifier:3; 34 | unsigned targetDisplayDeviceSessioMode:4; 35 | unsigned :1; 36 | 37 | unsigned sessionFunctionCode:8; 38 | unsigned requesterCaretDisplayLineIdentifier:8; 39 | 40 | unsigned :2; 41 | unsigned horizontalJustify:2; 42 | unsigned font:2; 43 | unsigned characterSet:2; 44 | 45 | }Status; 46 | }ArbTextReqSetDispParameters; 47 | 48 | void ServiceArbTextReqSetDispParameters(uint8_t *data); 49 | 50 | void SendArbTextReqSetDispParameters(ArbTextReqSetDispParameters *arbTextReqSetDispParameters); 51 | 52 | void Emulate_ArbTextReqSetDispParameters(void); 53 | 54 | #endif // ARB_TEXT_REQ_SET_DISP_PARAMETER_H 55 | -------------------------------------------------------------------------------- /Vehicle Drivers/VIN.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_VIN 3 | 4 | #include "main.h" 5 | #include "VIN.h" 6 | #include "can.h" 7 | 8 | #if defined GMLAN_V1 9 | 10 | unsigned char VIN_2_9[8]; 11 | unsigned char VIN_10_17[8]; 12 | unsigned char VIN_2_9_CheckedFlag = 0; 13 | unsigned char VIN_10_17_CheckedFlag = 0; 14 | 15 | void Service_VIN_2_9(unsigned char *data){ 16 | unsigned char i; 17 | if(VIN_2_9_CheckedFlag) { // already got vin so no need to save again 18 | return; 19 | } 20 | for(i = 0; i < 8; i++) { 21 | VIN_2_9[i] = data[i]; 22 | } 23 | VIN_2_9_CheckedFlag = 1; 24 | } 25 | 26 | void Service_VIN_10_17(unsigned char *data){ 27 | unsigned char i; 28 | if(VIN_10_17_CheckedFlag) { // already got vin so no need to save again 29 | return; 30 | } 31 | for(i = 0; i < 8; i++) { 32 | VIN_10_17[i] = data[i]; 33 | } 34 | VIN_10_17_CheckedFlag = 1; 35 | } 36 | 37 | int GetYear(void) { 38 | // todo return 10th digit as number 39 | return 0; 40 | } 41 | 42 | bool GetHatchbackFlag(void) { 43 | // todo return if hatchback 44 | return false; 45 | } 46 | 47 | void GetVIN_2_9(unsigned char *data) { 48 | int i; 49 | for(i = 0; i < 8; i++){ 50 | data[i] = VIN_2_9[i]; 51 | } 52 | } 53 | 54 | void GetVIN_10_17(unsigned char *data) { 55 | int i; 56 | for(i = 0; i < 8; i++){ 57 | data[i] = VIN_10_17[i]; 58 | } 59 | } 60 | 61 | #endif // GMLAN_V1 62 | 63 | #if defined FORD 64 | 65 | 66 | #endif // FORD 67 | 68 | #if defined CHRYSLER_LSFTCAN 69 | 70 | 71 | 72 | #endif // CHRYSLER_LSFTCAN 73 | 74 | #if defined CHYSLER_MSCAN 75 | 76 | 77 | #endif // MSCAN 78 | 79 | 80 | #endif // USE_VIN 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /Chksum16bit.c: -------------------------------------------------------------------------------- 1 | 2 | #include "main.h" 3 | #include "Chksum16bit.h" 4 | 5 | /* 6 | * Description: For validating Telemetry data. 7 | * The checksum is the first two bytes of the telemetry data. 8 | * Data should be in 2 bytes increments. 9 | * Input: Pointer to the data array, the total packet length and if to invert checksum value 10 | * Output: none 11 | * Return: True if checksum matches, false if checksum does not match calculated value. 12 | * 13 | */ 14 | bool ChkSum16_Validate(uint8_t *data, uint8_t len, bool invert) 15 | { 16 | uint16_t chksum = 0; 17 | uint32_t i = 0; 18 | 19 | for(i = 2; i < len; i += 2) 20 | { 21 | chksum += data[i] | (data[i+1] << 8); 22 | } 23 | if(invert) 24 | { 25 | chksum ^= 0xFFFF; // invert 26 | } 27 | if(chksum != (data[0] | (data[1] << 8))) 28 | { 29 | return false; 30 | } 31 | return true; 32 | } 33 | 34 | /* 35 | * Description: Takes a Telemetry packet and calculates the 16 bit checksum and places into the first 2 bytes of data packet. 36 | * Input: The Pointer to the data array, the packet length and to invert checksum value 37 | * Output: The data packet with added checksum 38 | */ 39 | void ChkSum16_Calculate(uint8_t *data, uint8_t len, bool invert) 40 | { 41 | uint16_t chksum = 0; 42 | uint32_t i = 0; 43 | 44 | for (i = 2; i < len; i += 2) 45 | { 46 | chksum += data[i] | (data[i+1] << 8); 47 | } 48 | 49 | if(invert) 50 | { 51 | chksum ^= 0xFFFF; // invert 52 | } 53 | 54 | data[0] = chksum; 55 | data[1] = chksum >> 8; 56 | } 57 | 58 | 59 | -------------------------------------------------------------------------------- /I2C_Queue_STM32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * I2C_Queue_STM32.h 3 | * 4 | * Created on: Oct 21, 2025 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_I2C_QUEUE_STM32_H_ 9 | #define INC_I2C_QUEUE_STM32_H_ 10 | 11 | 12 | typedef struct __I2C_GenericQueueDef 13 | { 14 | I2C_HandleTypeDef *i2c_instance; 15 | 16 | uint8_t deviceAddr; // the slave address of device 17 | uint8_t data[8]; 18 | uint8_t registerAddr[2]; // 8 or 16 bit address 19 | uint32_t dataSize; 20 | uint32_t regSize; // the size of the registerAddr, 1 or 2 bytes 21 | uint32_t timeout; // typically for STM32 that uses HAL timeout 22 | uint32_t transferType; // I2C_POLLING, I2C_INTERRUPT, I2C_DMA 23 | uint32_t readWriteType; // 24 | bool pending; 25 | 26 | void (*RxISR)(struct __I2C_GenericQueueDef *i2c); 27 | void (*TxISR)(struct __I2C_GenericQueueDef *i2c); // probably not needed but here nonetheless 28 | char *cmdPtr; // pointer to copy of command message 29 | }I2C_GenericQueueDef; 30 | 31 | typedef struct 32 | { 33 | I2C_GenericQueueDef *queueData; // pointer to queue buffer 34 | I2C_GenericQueueDef *msgToParse; // pointer to message to write/read 35 | RING_BUFF_STRUCT ptr; 36 | uint32_t queueSize; 37 | }I2C_QueueStruct_t; 38 | 39 | int I2C_QUEUE_Add(I2C_QueueStruct_t *queue, I2C_GenericQueueDef *i2c); 40 | int I2C_QUEUE_Transmit(I2C_QueueStruct_t *queue); 41 | 42 | int I2C_QUEUE_Master_Receive_Generic_Method(I2C_GenericQueueDef *i2c); 43 | int I2C_QUEUE_Master_Transmit_Generic_Method(I2C_GenericQueueDef *i2c); 44 | int I2C_QUEUE_Mem_Read_Generic_Method(I2C_GenericQueueDef *i2c); 45 | int I2C_QUEUE_Mem_Write_Generic_Method(I2C_GenericQueueDef *i2c); 46 | 47 | #endif /* INC_I2C_QUEUE_STM32_H_ */ 48 | -------------------------------------------------------------------------------- /Flash_ReadWrite_Drv_STM32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Flash_ReadWrite_Drv_STM32.c 3 | * 4 | * Created on: Oct 10, 2024 5 | * Author: codek 6 | */ 7 | 8 | 9 | 10 | #include "main.h" 11 | 12 | 13 | /* 14 | * Description: 15 | */ 16 | int FLASH_WriteDoubleWord(FlashWriteInit_t *flashMsg) 17 | { 18 | int status = 0; 19 | HAL_StatusTypeDef hal_status; 20 | uint8_t data[8]; 21 | int i, n = 0; 22 | uint8_t *dataPtr; 23 | 24 | dataPtr = flashMsg->data; 25 | 26 | HAL_FLASH_Unlock(); 27 | 28 | hal_status = HAL_FLASHEx_Erase(&flashMsg->flashEraseInit, &flashMsg->PageError); 29 | if(hal_status != HAL_OK) 30 | { 31 | return FLASH_ERASED_FAILED; 32 | } 33 | 34 | for(i = 0, n = 0; i < flashMsg->doubleWordAmount; i++, n += FLASH_DOUBLE_WORD_SIZE) // each write is a double word 35 | { 36 | memcpy(&data, &dataPtr[n], FLASH_DOUBLE_WORD_SIZE); 37 | hal_status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, flashMsg->address, (uint64_t)(*((uint64_t *)((uint32_t)data)))); 38 | if(hal_status != HAL_OK) 39 | { 40 | return FLASH_WRITE_FAILED; 41 | } 42 | flashMsg->address += FLASH_DOUBLE_WORD_SIZE; // double word 43 | } 44 | 45 | HAL_FLASH_Lock(); 46 | 47 | return status; 48 | } 49 | 50 | /* 51 | * Description: Read 1 byte from Address. 52 | */ 53 | uint8_t FLASH_DATA_Read(uint32_t address) 54 | { 55 | return (*(uint8_t *)(address)); 56 | } 57 | 58 | /* 59 | * Description: Read multiple bytes. 60 | */ 61 | int FLASH_DATA_ReadMultiBytes(FlashReadInit_t *flash) 62 | { 63 | int i = 0; 64 | 65 | for(i = 0; i < flash->count; i++) 66 | { 67 | flash->data[i] = (*(uint8_t *)(flash->address)); 68 | flash->address += 1; 69 | } 70 | 71 | return NO_ERROR; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /TUSB1002.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TUSB1002.h 3 | * 4 | * Created on: Aug 19, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SRC_TUSB1002_H_ 9 | #define SRC_TUSB1002_H_ 10 | 11 | 12 | 13 | enum{ 14 | TUSB1002_EQ = 1, 15 | TUSB1002_VOD 16 | }EQ_VOD; 17 | 18 | 19 | enum{ 20 | CFG1_S1, 21 | CFG1_S2, 22 | CFG2_S1, 23 | CFG2_S2, 24 | RX_EQ1_S1, 25 | RX_EQ1_S2, 26 | RX_EQ2_S1, 27 | RX_EQ2_S2, 28 | TX_EQ1_S1, 29 | TX_EQ1_S2, 30 | TX_EQ2_S1, 31 | TX_EQ2_S2, 32 | 33 | CFG1_S1_REDRV2, // 12 34 | CFG1_S2_REDRV2, // 13 35 | CFG2_S1_REDRV2, // 14 36 | CFG2_S2_REDRV2, // 15 37 | RX_EQ1_S1_REDRV2, 38 | RX_EQ1_S2_REDRV2, 39 | RX_EQ2_S1_REDRV2, 40 | RX_EQ2_S2_REDRV2, 41 | TX_EQ1_S1_REDRV2, 42 | TX_EQ1_S2_REDRV2, 43 | TX_EQ2_S1_REDRV2, 44 | TX_EQ2_S2_REDRV2, 45 | 46 | REDRIVER1_EN, 47 | REDRIVER2_EN 48 | }; 49 | 50 | void TUSB1002_Init(void); 51 | 52 | void TUSB1002_SetRedriver1_Rx_EQ(uint8_t idxPtr); 53 | void TUSB1002_SetRedriver1_Tx_EQ(uint8_t idxPtr); 54 | void TUSB1002_SetRedriver1_Cfg_VOD(uint8_t idxPtr); 55 | 56 | void TUSB1002_SetRedriver2_Rx_EQ(uint8_t idxPtr); 57 | void TUSB1002_SetRedriver2_Tx_EQ(uint8_t idxPtr); 58 | void TUSB1002_SetRedriver2_Cfg_VOD(uint8_t idxPtr); 59 | 60 | void TUSB1002_PulseRedriver1_En(void); 61 | void TUSB1002_PulseRedriver2_En(void); 62 | 63 | void TUSB1002_SetRedriver1_En(void); 64 | void TUSB1002_SetRedriver2_En(void); 65 | 66 | void TUSB1002_ClearRedriver1_En(void); 67 | void TUSB1002_ClearRedriver2_En(void); 68 | 69 | void TUSB1002_Pulse1En(bool status); 70 | void TUSB1002_Pulse2En(bool status); 71 | 72 | void TUSB1002_SetRedriver1_En(void); 73 | void TUSB1002_SetRedriver2_En(void); 74 | 75 | 76 | 77 | #endif /* SRC_TUSB1002_H_ */ 78 | -------------------------------------------------------------------------------- /Vehicle Drivers/FORD_CAN_ID.h: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_FORD_CAN_ID 3 | #ifndef FORD_CAN_ID 4 | #define FORD_CAN_ID 5 | 6 | //125kbs? 7 | 8 | #define POWER_MODE_ID 0x3A0L 9 | #define VSS_ID 0x423L 10 | #define DIMMER_ID 0x3ABL 11 | #define DIMMER2_ID 0x10BL // 2005 Mustang 12 | #define DIMMER4_ID 0x3B3L 13 | #define PARKING_LIGHT_ID 0x3B8 // 2005 Mustang 14 | #define GEAR_INFORMATION_ID 0x3B0L // 2005 Mustang 15 | #define DOOR_STATUS_ID 0x3B1L 16 | #define DOOR_STATUS2_ID 0x3C4L 17 | #define PARKING_BRAKE_ID 0x3C3L 18 | #define PARKING_BRAKE1_ID 0x3C2L 19 | #define PARKING_BRAKE2_ID 0x3C1L // 2005 Mustang 20 | #define RAP_ID 0x3B6 // 2005 Mustang 21 | #define RAP_ID 0x3C6 // 2010 Mustang 22 | #define AUDIO_MASTER_REMOTE_RECEIVER_COMMAND_ID 0x2DB // 2005 Mustang 23 | #define VIN_ID 0x22F 24 | #define SATELLITE_RADIO_ID 0x3EA // 2005 Mustang 25 | #define SATELLITE_RADIO2_ID 0x335 // 2005 Mustang 26 | 27 | #define RSE_BUTTON_ID 0x2DEL 28 | #define RSC_BUTTON_ID 0x2DFL 29 | #define SYNC_PRESENT_ID 0x541L 30 | #define SYNC_STATUS_ID 0x3EBL 31 | #define SYNC_TEXT_ID 0x333L 32 | #define SYNC_SEND_MODE_SWITCH_340_ID 0x340L 33 | #define SYNC_SEND_CONF_MODE_SWITCH_350_ID 0x350L 34 | #define SYNC_TEXT_MODE_ID 0x332L 35 | #define SYNC_50B_STATUS_ID 0x50BL 36 | #define SYNC_511_STATUS_ID 0x511L 37 | #define SYNC_503_STATUS_ID 0x503L 38 | #define OE_LCD_500_ID 0x55CL 39 | #define OE_LCD_RESP_ID 0x324L 40 | #define SAT_500_ID 0x542L 41 | #define SAT_TEXT_ID 0x335L 42 | #define SAT_TEXT_MODE_ID 0x334L 43 | #define LCD_BUTTON_PRESS_ID 0x2E1L 44 | #define DIGITAL_AMP_500_ID 0x546L 45 | #define RSE_500_ID 0x512L 46 | #define DIGITAL_AMP_SETTINGDS_ID 0x3EDL 47 | 48 | 49 | #endif // FORD_CAN_ID 50 | #endif // USE_FORD_CAN_ID 51 | -------------------------------------------------------------------------------- /Xilinx/TUSB1002.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TUSB1002.h 3 | * 4 | * Created on: Aug 19, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef SRC_TUSB1002_H_ 9 | #define SRC_TUSB1002_H_ 10 | 11 | 12 | 13 | enum{ 14 | TUSB1002_EQ = 1, 15 | TUSB1002_VOD 16 | }EQ_VOD; 17 | 18 | 19 | enum{ 20 | CFG1_S1, 21 | CFG1_S2, 22 | CFG2_S1, 23 | CFG2_S2, 24 | RX_EQ1_S1, 25 | RX_EQ1_S2, 26 | RX_EQ2_S1, 27 | RX_EQ2_S2, 28 | TX_EQ1_S1, 29 | TX_EQ1_S2, 30 | TX_EQ2_S1, 31 | TX_EQ2_S2, 32 | 33 | CFG1_S1_REDRV2, // 12 34 | CFG1_S2_REDRV2, // 13 35 | CFG2_S1_REDRV2, // 14 36 | CFG2_S2_REDRV2, // 15 37 | RX_EQ1_S1_REDRV2, 38 | RX_EQ1_S2_REDRV2, 39 | RX_EQ2_S1_REDRV2, 40 | RX_EQ2_S2_REDRV2, 41 | TX_EQ1_S1_REDRV2, 42 | TX_EQ1_S2_REDRV2, 43 | TX_EQ2_S1_REDRV2, 44 | TX_EQ2_S2_REDRV2, 45 | 46 | REDRIVER1_EN, 47 | REDRIVER2_EN 48 | }; 49 | 50 | void TUSB1002_Init(void); 51 | 52 | void TUSB1002_SetRedriver1_Rx_EQ(uint8_t idxPtr); 53 | void TUSB1002_SetRedriver1_Tx_EQ(uint8_t idxPtr); 54 | void TUSB1002_SetRedriver1_Cfg_VOD(uint8_t idxPtr); 55 | 56 | void TUSB1002_SetRedriver2_Rx_EQ(uint8_t idxPtr); 57 | void TUSB1002_SetRedriver2_Tx_EQ(uint8_t idxPtr); 58 | void TUSB1002_SetRedriver2_Cfg_VOD(uint8_t idxPtr); 59 | 60 | void TUSB1002_PulseRedriver1_En(void); 61 | void TUSB1002_PulseRedriver2_En(void); 62 | 63 | void TUSB1002_SetRedriver1_En(void); 64 | void TUSB1002_SetRedriver2_En(void); 65 | 66 | void TUSB1002_ClearRedriver1_En(void); 67 | void TUSB1002_ClearRedriver2_En(void); 68 | 69 | void TUSB1002_Pulse1En(bool status); 70 | void TUSB1002_Pulse2En(bool status); 71 | 72 | void TUSB1002_SetRedriver1_En(void); 73 | void TUSB1002_SetRedriver2_En(void); 74 | 75 | 76 | 77 | #endif /* SRC_TUSB1002_H_ */ 78 | -------------------------------------------------------------------------------- /ErrorStatus.c: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | * @attention 4 | * 5 | * Copyright (c) 2025 Karl Yamashita 6 | * All rights reserved. 7 | * 8 | * This software is licensed under terms that can be found in the LICENSE file 9 | * in the root directory of this software component. 10 | * If no LICENSE file comes with this software, it is provided AS-IS. 11 | * 12 | ****************************************************************************** 13 | */ 14 | 15 | /* 16 | * ErrorStatus.c 17 | * 18 | * Created on: Mar 21, 2022 19 | * Author: karl.yamashita 20 | */ 21 | 22 | #include "main.h" 23 | #include "ErrorStatus.h" 24 | 25 | 26 | 27 | /* 28 | * Description: Returns string based off error code. 29 | * 30 | * 31 | */ 32 | void GetErrorString(int errorCode, char *str){ 33 | switch(errorCode){ 34 | case NO_ERROR: 35 | strcpy(str, "OK"); 36 | break; 37 | case COMMAND_UNKNOWN: 38 | strcpy(str, "ERROR-Command Unknown"); 39 | break; 40 | case VALUE_OUT_OF_RANGE: 41 | strcpy(str, "ERROR-Value out of range"); 42 | break; 43 | case VALUE_NOT_VALID: 44 | strcpy(str, "ERROR-Value not valid"); 45 | break; 46 | 47 | case ERR_1: 48 | strcpy(str, "ERROR-DEBUG 1"); 49 | break; 50 | case ERR_2: 51 | strcpy(str, "ERROR-DEBUG 2"); 52 | break; 53 | case ERR_3: 54 | strcpy(str, "ERROR-DEBUG 3"); 55 | break; 56 | case ERR_4: 57 | strcpy(str, "ERROR-DEBUG 4"); 58 | break; 59 | default: 60 | strcpy(str, "ERROR-returned code not a valid error"); 61 | break; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Xilinx/InterruptController_Init.c: -------------------------------------------------------------------------------- 1 | /* 2 | * InterruptController_Init.c 3 | * 4 | * Created on: Jun 4, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #include "main.h" 9 | #include "InterruptController_Init.h" 10 | 11 | //#define Init_InterruptControllerPrintLine // uncomment to print debug messages 12 | 13 | // interrupt controller variable 14 | XIntc InterruptController; // 15 | 16 | #define INTC_DEVICE_ID XPAR_INTC_0_DEVICE_ID 17 | 18 | /* 19 | * Description: 20 | * 21 | * 22 | */ 23 | int Init_InterruptController(void){ 24 | int Status; 25 | #ifdef Init_InterruptControllerPrintLine 26 | PrintLine("Init_InterruptController()"); 27 | #endif 28 | /* 29 | * Initialize the interrupt controller driver so that it is ready to 30 | * use. 31 | */ 32 | Status = XIntc_Initialize(&InterruptController, INTC_DEVICE_ID); 33 | if (Status != XST_SUCCESS) { 34 | return XST_FAILURE; 35 | } 36 | #ifdef Init_InterruptControllerPrintLine 37 | PrintLine("XIntc_Initialize success"); 38 | #endif 39 | /* 40 | * Perform a self-test to ensure that the hardware was built 41 | * correctly. 42 | */ 43 | Status = XIntc_SelfTest(&InterruptController); 44 | if (Status != XST_SUCCESS) { 45 | return XST_FAILURE; 46 | } 47 | #ifdef Init_InterruptControllerPrintLine 48 | PrintLine("XIntc_SelfTest success"); 49 | #endif 50 | /* 51 | * Start the interrupt controller such that interrupts are recognized 52 | * and handled by the processor. 53 | */ 54 | Status = XIntc_Start(&InterruptController, XIN_REAL_MODE); 55 | if (Status != XST_SUCCESS) { 56 | return XST_FAILURE; 57 | } 58 | #ifdef Init_InterruptControllerPrintLine 59 | PrintLine("XIntc_Start success"); 60 | #endif 61 | return XST_SUCCESS; 62 | } 63 | 64 | 65 | -------------------------------------------------------------------------------- /Vehicle Drivers/NCA_From_SDAR.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_NCA_FROM_SDAR 3 | #include "main.h" 4 | #include "NCA_From_SDAR.h" 5 | #include "CAN.h" 6 | #include "CAN_Buffer.h" 7 | #include "GMLAN_CAN_ID.h" 8 | #include "mTimers.h" 9 | 10 | 11 | uint8_t NCA_From_SDAR_Timer = 0;// timer instance 12 | bool sdarPresentFlag = false; 13 | 14 | /* 15 | function: set a flag when receiving a CAN message. There is no data to be passed. 16 | input: none 17 | output: none 18 | */ 19 | void SetNCA_From_SDAR_PresentFlag(bool status) { 20 | sdarPresentFlag = status; 21 | } 22 | 23 | bool GetNCA_From_SDAR_PresentFlag(void) { 24 | return sdarPresentFlag; 25 | } 26 | 27 | /* 28 | function: Send NCA_From_SDAR ID with delay. You can call this in a polling routine with a delay like 1.2seconds 29 | or respond to Radio's NCA with no delay 30 | input: the delay time. 0 = send right away. 31 | output: none 32 | */ 33 | void SendNCA_FROM_SDAR(uint32_t delay) { 34 | if(NCA_From_SDAR_Timer == 0) { 35 | NCA_From_SDAR_Timer = CreateTimer(); 36 | } 37 | CanTxMsgTypeDef canMessage; 38 | 39 | if(GetTimer(NCA_From_SDAR_Timer) >= delay) { 40 | SetTimer(NCA_From_SDAR_Timer, 0);// clear timer for next transmission 41 | canMessage.ExtId = NCA_FROM_SDAR_ID; // Set extended ID for transmit message 42 | canMessage.DLC = 0; 43 | canMessage.IDE = CAN_ID_EXT; 44 | canMessage.RTR = CAN_RTR_DATA; 45 | AddTxBuffer1(&canMessage); 46 | } 47 | } 48 | 49 | 50 | /* 51 | function: if no XM present then emulate the data so radio is happy 52 | input: none 53 | output: none 54 | */ 55 | void Emulate_NCA_From_SDAR(void) { 56 | if(sdarPresentFlag == true) return;// we don't need to emulate 57 | SendNCA_FROM_SDAR(0); // send with no delay 58 | } 59 | #endif // USE_NCA_FROM_SDAR 60 | -------------------------------------------------------------------------------- /Vehicle Drivers/VehicleSpeed.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_VEHICLE_SPEED 3 | #include "main.h" 4 | #include "VehicleSpeed.h" 5 | 6 | #ifdef GMLAN_V1 7 | 8 | 9 | unsigned char vssData[2]; 10 | 11 | void ServiceVehicleSpeed(unsigned char *data) { 12 | vssData[0] = data[2]; 13 | vssData[1] = data[3]; 14 | } 15 | 16 | unsigned int GetVehicleSpeed(void) { 17 | unsigned int vssSpeed; 18 | if ((vssData[0] > 0 || vssData[1] > 0) && vssData[0] != 0xFF) { 19 | vssSpeed = vssData[0]; 20 | vssSpeed = (vssSpeed << 8) + vssData[1]; 21 | vssSpeed = vssSpeed & 0x7FFF; // only 15 bits used per GM specs 22 | #if defined USE_KM_H 23 | return (vssSpeed >> 6); // vssSpeed * 0.015625 = km/h 24 | #else 25 | return (vssSpeed >> 6) * 0.62137119223733; // vssSpeed * 0.015625 = MPH 26 | #endif 27 | } 28 | return 0; 29 | } 30 | 31 | 32 | 33 | #endif // GMLAN_V1 34 | 35 | #ifdef CHRYSLER_V5 36 | uint8_t vssData; 37 | 38 | void ServiceVehicleSpeed(unsigned char *data) { 39 | vssData = data[7]; 40 | } 41 | 42 | /* 43 | return value in mph 44 | */ 45 | uint8_t GetVehicleSpeed(void) { 46 | return vssData; 47 | } 48 | 49 | #endif // CHRYSLER_V5 50 | 51 | #ifdef CHRYSLER_V3 52 | uint8_t vssData; 53 | 54 | void ServiceVehicleSpeed(unsigned char *data) { 55 | vssData = data[7]; 56 | } 57 | 58 | /* 59 | return value in mph 60 | */ 61 | uint8_t GetVehicleSpeed(void) { 62 | return vssData; 63 | } 64 | 65 | #endif // CHRYSLER_V3 66 | 67 | #ifdef CHRYSLER_V2 68 | uint8_t vssData; 69 | 70 | void ServiceVehicleSpeed(unsigned char *data) { 71 | vssData = data[7]; 72 | } 73 | 74 | /* 75 | return value in mph 76 | */ 77 | uint8_t GetVehicleSpeed(void) { 78 | return vssData; 79 | } 80 | 81 | #endif // CHRYSLER_V2 82 | 83 | #endif // USE_VEHICLE_SPEED 84 | 85 | -------------------------------------------------------------------------------- /UART_DMA_Handler_STM32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * UART_DMA_Handler.h 3 | * 4 | * Created on: Jan 3, 2023 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_UART_DMA_HANDLER_H_ 9 | #define INC_UART_DMA_HANDLER_H_ 10 | 11 | // USER DEFINES User can adjust these defines to fit their project requirements 12 | #define UART_DMA_DATA_SIZE 128 13 | #define UART_DMA_QUEUE_SIZE 8 14 | // END USER DEFINES 15 | // ************************************************** 16 | // ********* Do not modify code below here ********** 17 | // ************************************************** 18 | typedef struct 19 | { 20 | uint32_t size; // move to top to byte align 21 | uint8_t data[UART_DMA_DATA_SIZE]; 22 | }UART_DMA_Data; // this is used in queue structure 23 | 24 | typedef struct 25 | { 26 | UART_HandleTypeDef *huart; 27 | struct 28 | { 29 | UART_DMA_Data queue[UART_DMA_QUEUE_SIZE]; 30 | UART_DMA_Data *msgToParse; 31 | RING_BUFF_STRUCT ptr; 32 | uint32_t queueSize; 33 | HAL_StatusTypeDef hal_status; 34 | }rx; 35 | struct 36 | { 37 | UART_DMA_Data queue[UART_DMA_QUEUE_SIZE]; 38 | RING_BUFF_STRUCT ptr; 39 | uint32_t queueSize; 40 | bool txPending; 41 | }tx; 42 | }UART_DMA_QueueStruct; 43 | 44 | 45 | void UART_DMA_Init(UART_DMA_QueueStruct *msg, UART_HandleTypeDef *huart); 46 | void UART_DMA_EnableRxInterrupt(UART_DMA_QueueStruct *msg); 47 | void UART_DMA_CheckRxInterruptErrorFlag(UART_DMA_QueueStruct *msg); 48 | int UART_DMA_MsgRdy(UART_DMA_QueueStruct *msg); 49 | void UART_DMA_NotifyUser(UART_DMA_QueueStruct *msg, char *str, uint32_t size, bool lineFeed); 50 | 51 | void UART_DMA_TX_AddMessageToBuffer(UART_DMA_QueueStruct *msg, uint8_t *data, uint32_t size); 52 | void UART_DMA_SendMessage(UART_DMA_QueueStruct * msg); 53 | 54 | 55 | #endif /* INC_UART_DMA_HANDLER_H_ */ 56 | -------------------------------------------------------------------------------- /Xilinx/SPI_ReadWrite.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPI_ReadWrite.c 3 | * 4 | * Created on: Jul 27, 2021 5 | * Author: karl.yamashita 6 | */ 7 | 8 | 9 | #include "main.h" 10 | #include "SPI_ReadWrite.h" 11 | 12 | //#define SPI_ReadWrite_PrintLine 13 | 14 | extern XSpi Spi; 15 | 16 | 17 | /* 18 | * Description: Write data. 19 | * 20 | * 21 | */ 22 | int SPI_WriteData(uint8_t *SendBufPtr, uint8_t ByteCount){ 23 | int status = 0; 24 | #ifdef SPI_ReadWrite_PrintLine 25 | // PrintLine("SPI_WriteData()"); 26 | #endif 27 | SPI_SetTransferInProgress(true); 28 | status = XSpi_Transfer(&Spi, SendBufPtr, NULL, ByteCount); 29 | if(status != 0){ 30 | return status; 31 | } 32 | 33 | while (SPI_GetTransferInProgress()); 34 | if(SPI_GetErrorCount() != 0) { 35 | SPI_SetErrorCount(0); 36 | return XST_FAILURE; 37 | } 38 | 39 | #ifdef SPI_ReadWrite_PrintLine 40 | PrintLine("SPI_WriteData success"); 41 | #endif 42 | return status; 43 | } 44 | 45 | /* 46 | * Description: Send and receive data 47 | * 48 | * 49 | */ 50 | int SPI_TransferData(uint8_t *SendBufPtr, uint8_t *RecvBufPtr, uint8_t ByteCount){ 51 | int status = 0; 52 | 53 | #ifdef SPI_ReadWrite_PrintLine 54 | // PrintLine("SPI_TransferData()"); 55 | #endif 56 | SPI_SetTransferInProgress(true); 57 | status = XSpi_Transfer(&Spi, SendBufPtr, RecvBufPtr, ByteCount); 58 | if(status != 0){ 59 | return status; 60 | } 61 | 62 | while (SPI_GetTransferInProgress()); 63 | if(SPI_GetErrorCount() != 0) { 64 | SPI_SetErrorCount(0); 65 | return XST_FAILURE; 66 | } 67 | #ifdef SPI_ReadWrite_PrintLine 68 | PrintLine("SPI_TransferData success"); 69 | #endif 70 | return status; 71 | } 72 | 73 | /* 74 | * 75 | * 76 | * 77 | */ 78 | int SPI_WaitForNotBusy(void){ 79 | int status = 0; 80 | 81 | 82 | return status; 83 | } 84 | 85 | 86 | -------------------------------------------------------------------------------- /CAN_Filter.c: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | * @attention 4 | * 5 | * Copyright (c) 2025 Karl Yamashita 6 | * All rights reserved. 7 | * 8 | * This software is licensed under terms that can be found in the LICENSE file 9 | * in the root directory of this software component. 10 | * If no LICENSE file comes with this software, it is provided AS-IS. 11 | * 12 | ****************************************************************************** 13 | */ 14 | 15 | #include "main.h" 16 | 17 | 18 | /* 19 | function: Set CAN filter to pass all ID's 20 | input: hcan instance 21 | output: none 22 | */ 23 | void CAN_SetFilter(CAN_MsgStruct *msg) 24 | { 25 | static CAN_FilterTypeDef sFilterConfig; 26 | 27 | if(msg->hcan == &hcan) 28 | { 29 | sFilterConfig.FilterBank = 0; 30 | } 31 | 32 | sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK; 33 | sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT; 34 | sFilterConfig.FilterIdHigh = 0x0000; 35 | sFilterConfig.FilterIdLow = 0x0000; 36 | sFilterConfig.FilterMaskIdHigh = 0x0000; 37 | sFilterConfig.FilterMaskIdLow = 0x0000; 38 | sFilterConfig.FilterFIFOAssignment = CAN_FILTER_FIFO0; 39 | sFilterConfig.FilterActivation = CAN_FILTER_ENABLE; 40 | 41 | if(HAL_CAN_ConfigFilter(msg->hcan, &sFilterConfig) != HAL_OK) 42 | { 43 | Error_Handler(); // Error_Handler should never be called, so we won't worry about handling these errors. 44 | } 45 | 46 | if(HAL_CAN_Start(msg->hcan) != HAL_OK) 47 | { 48 | Error_Handler(); 49 | } 50 | 51 | if (HAL_CAN_ActivateNotification(msg->hcan, CAN_IT_RX_FIFO0_MSG_PENDING | CAN_IT_TX_MAILBOX_EMPTY) != HAL_OK) 52 | { 53 | Error_Handler(); 54 | } 55 | } 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /CAN_Buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | * @attention 4 | * 5 | * Copyright (c) 2025 Karl Yamashita 6 | * All rights reserved. 7 | * 8 | * This software is licensed under terms that can be found in the LICENSE file 9 | * in the root directory of this software component. 10 | * If no LICENSE file comes with this software, it is provided AS-IS. 11 | * 12 | ****************************************************************************** 13 | */ 14 | 15 | #ifndef CAN_BUFFER_H 16 | #define CAN_BUFFER_H 17 | 18 | 19 | 20 | // Receive 21 | typedef struct CanRxMsgTypeDef 22 | { 23 | CAN_RxHeaderTypeDef header; 24 | uint8_t data[8]; 25 | }CanRxMsgTypeDef; 26 | 27 | // Transmit 28 | typedef struct CanTxMsgTypeDef 29 | { 30 | CAN_TxHeaderTypeDef header; 31 | uint8_t data[8]; 32 | }CanTxMsgTypeDef; 33 | 34 | typedef struct 35 | { 36 | CAN_HandleTypeDef *hcan; // CAN instance 37 | 38 | // Rx 39 | CanRxMsgTypeDef *rxQueue; 40 | uint32_t rxQueueSize; 41 | CanRxMsgTypeDef *msgToParse; // pointer to latest queue 42 | RING_BUFF_STRUCT rxPtr; // queue pointer 43 | bool canBusActive; // used for CAN bus activity to keep STM32 from going to sleep. 44 | uint32_t rxCounter; // for debugging 45 | // Tx 46 | CanTxMsgTypeDef *txQueue; 47 | uint32_t txQueueSize; 48 | RING_BUFF_STRUCT txPtr; // queue pointer 49 | uint32_t txCounter; // for debugging 50 | }CAN_MsgStruct; 51 | 52 | int CAN_SendMessage(CAN_MsgStruct *msg); 53 | int CAN_AddTxBuffer(CAN_MsgStruct *msg, CanTxMsgTypeDef *txData); 54 | bool CAN_DataAvailable(CAN_MsgStruct *msg); 55 | bool CAN_GetBusActivity(CAN_MsgStruct *msg); 56 | void CAN_ClearBusActivity(CAN_MsgStruct *msg); 57 | void MsgCopy(CanTxMsgTypeDef *TxMsg, CanRxMsgTypeDef *RxMsg); 58 | 59 | #endif // CAN_BUFFER_H 60 | 61 | -------------------------------------------------------------------------------- /Sleep.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #include "main.h" 3 | #ifdef USE_SLEEP 4 | 5 | #include "Sleep.h" 6 | #include "mTimers.h" 7 | #include "gpio.h" 8 | #include "GPIO_Ports.h" 9 | 10 | #if defined GMLAN_V1 11 | #include "CAN_TransceiverGMLAN.h" 12 | #endif 13 | #if defined MS_CAN 14 | #include "CAN_TransceiverMS.h" 15 | #endif 16 | 17 | 18 | uint8_t sleepTimer = 0; // timer instance 19 | 20 | void SleepCheck(uint32_t theSleepTime, Callback callback) { 21 | if(sleepTimer == 0) { 22 | sleepTimer = CreateTimer(); 23 | } 24 | if(GetTimer(sleepTimer) >= theSleepTime) { 25 | callback(1); 26 | } 27 | } 28 | 29 | // call this in CAN receive interrupt 30 | void SleepReset(void) { 31 | if(sleepTimer == 0) return; // no timer created 32 | SetTimer(sleepTimer, 0);// clear timer 33 | } 34 | 35 | /* 36 | 37 | Here are some example call back routines to use in PollingRoutines. One is for single CAN transceiver and the other is for Dual CAN transcivers 38 | 39 | void GotoSleepCallback(int status) { // Single CAN Transceiver 40 | if(status) { // if status is true then go to sleep 41 | // todo turn off other stuff 42 | 43 | 44 | // do not modify code below 45 | PortB_Off(LED1_Blue_Pin); 46 | PortB_Off(LED2_Red_Pin); 47 | CAN_TransceiverSleep(); 48 | __WFI(); // todo wakes up from unknown interrupt, need to fix 49 | InitCAN_Transceiver(); 50 | } 51 | } 52 | 53 | void GotoSleepCallback(int status) { // Dual CAN transceivers 54 | if(status) { // if status is true then go to sleep 55 | // todo turn off other stuff 56 | 57 | 58 | // do not modify code below 59 | PortC_Off(LED1_Blue_Pin); 60 | PortC_Off(LED2_Red_Pin); 61 | DualCanTransceiverSleep(); 62 | __WFI(); // todo wakes up from unknown interrupt, need to fix 63 | InitDualCanTransceiver(); 64 | } 65 | } 66 | */ 67 | 68 | #endif // USE_SLEEP 69 | 70 | -------------------------------------------------------------------------------- /Flash_Data_Handler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Flash_Data_Handler.h 3 | * 4 | * Created on: Oct 14, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_SERIALPARTPROGRAMMING_H_ 9 | #define INC_SERIALPARTPROGRAMMING_H_ 10 | 11 | 12 | #define FLASH_DATA_STRUCT_AMOUNT 8 // The amount of FLASH_Data_t used in FLASH_SerialPartNumber_t 13 | 14 | 15 | enum { 16 | FLASH_TYPE_SERIAL, 17 | FLASH_TYPE_PART, 18 | FLASH_TYPE_SLAVERAIL, 19 | FLASH_TYPE_VOUTCOMMAND, 20 | FLASH_TYPE_ADC_CAL_1, 21 | FLASH_TYPE_ADC_CAL_2, 22 | FLASH_TYPE_ADC_CAL_3, 23 | FLASH_TYPE_INFO_1, 24 | }; 25 | 26 | // data structure for saving serial/part number. 27 | typedef struct 28 | { 29 | uint8_t data[FLASH_STRING_DATA_SIZE]; 30 | }FLASH_Data_t; 31 | 32 | typedef union 33 | { 34 | struct 35 | { 36 | uint8_t data[FLASH_WRITE_DOUBLE_WORD_SIZE]; 37 | }Bytes; 38 | struct 39 | { 40 | FLASH_Data_t serial; 41 | FLASH_Data_t part; 42 | FLASH_Data_t slaveRail; 43 | FLASH_Data_t voutCommand; 44 | FLASH_Data_t adcCalibration_1; // LTM4681_SNS 45 | FLASH_Data_t adcCalibration_2; // OP_CRNT_SNS 46 | FLASH_Data_t adcCalibration_3; // LTM Vout 47 | FLASH_Data_t info1;// be sure to update #define FLASH_DATA_STRUCT_AMOUNT for every FLASH_Data_t added to this structure 48 | }Status; 49 | }FLASH_DataStruct_t; 50 | 51 | 52 | int FLASH_DATA_SetSerial(char *msg); 53 | int FLASH_DATA_SetPart(char *msg); 54 | int FLASH_DATA_GetSerial(char *retStr); 55 | int FLASH_DATA_GetPart(char *retStr); 56 | int FLASH_DATA_SetSlaveRail(char *msg); 57 | int FLASH_DATA_GetSlaveRail(char *retStr); 58 | int FLASH_DATA_SetInfo(uint8_t ptr, char *retStr); 59 | int FLASH_DATA_GetInfo(uint8_t ptr, char *retStr); 60 | 61 | int FLASH_DATA_Set_Interpolation(Interpolation_t *interpol, char *msg); 62 | int FLASH_DATA_Get_String(uint8_t type, char *retStr); 63 | 64 | #endif /* INC_SERIALPARTPROGRAMMING_H_ */ 65 | -------------------------------------------------------------------------------- /Vehicle Drivers/Rap.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #if defined USE_RAP 3 | 4 | #include "main.h" 5 | #include "Rap.h" 6 | #include "mTimers.h" 7 | #include "Sleep.h" 8 | 9 | #ifdef GMLAN_V1 10 | 11 | /* 12 | the steps needed to get rap timer working 13 | 1. Call SetRapTimerFlag to enable/disable rap timer. 14 | 2. call CheckRapStatus in a polling routine 15 | */ 16 | 17 | uint8_t rapStatusTimer = 0; // timer instance 18 | bool rapTimerFlag = false; 19 | 20 | // call this to set/clear flag 21 | void SetRapTimerFlag(bool flag) { 22 | static bool timerReseted = false; 23 | if(rapStatusTimer == 0) { 24 | rapStatusTimer = CreateTimer(); 25 | } 26 | if(flag == true && timerReseted == false) { 27 | SetTimer(rapStatusTimer, 0);// clear timer 28 | timerReseted = true; 29 | rapTimerFlag = true; 30 | } else if(flag == false) { 31 | timerReseted = false; 32 | rapTimerFlag = flag; 33 | } 34 | } 35 | 36 | // call this in polling routine. If time is reached then call rapCallback routine 37 | void CheckRapStatus(uint32_t rapTimer, Callback callback) { 38 | if(rapTimerFlag != true) return; // if flag is not set then we're not doing rap yet 39 | if(GetTimer(rapStatusTimer) >= rapTimer) { // wait on specific time then do callback 40 | callback(true); 41 | } 42 | } 43 | #endif // USE_GMLAN_V1 44 | 45 | #if defined CHRYSLER_V2 46 | 47 | uint8_t rapModeFlag = 0; 48 | void ServiceRapMode(uint8_t *data){ 49 | rapModeFlag = (data[1] & 0x02) >> 1; // byte1, bit1 50 | } 51 | 52 | uint8_t GetRapModeFlag(void) { 53 | return rapModeFlag; 54 | } 55 | #endif // CHRYSLER_V2 56 | 57 | #if defined CHRYSLER_V5 58 | 59 | uint8_t rapModeFlag = 0; 60 | void ServiceRapMode(uint8_t *data){ 61 | rapModeFlag = data[0] & 0x01; // byte0, bit0 62 | } 63 | 64 | uint8_t GetRapModeFlag(void) { 65 | return rapModeFlag; 66 | } 67 | #endif // CHRYSLER_V5 68 | 69 | #endif // USE_RAP 70 | 71 | -------------------------------------------------------------------------------- /PollingRoutine.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | ****************************************************************************** 4 | * @attention 5 | * 6 | * Copyright (c) 2025 Karl Yamashita 7 | * All rights reserved. 8 | * 9 | * This software is licensed under terms that can be found in the LICENSE file 10 | * in the root directory of this software component. 11 | * If no LICENSE file comes with this software, it is provided AS-IS. 12 | * 13 | ****************************************************************************** 14 | */ 15 | 16 | /* 17 | * PollingRoutine.h 18 | * 19 | * Created on: Oct 24, 2023 20 | * Author: karl.yamashita 21 | * 22 | * 23 | * Template 24 | */ 25 | 26 | #ifndef INC_POLLINGROUTINE_H_ 27 | #define INC_POLLINGROUTINE_H_ 28 | 29 | 30 | /* 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #define Nop() asm(" NOP ") 41 | 42 | // most commonly used. Uncomment if needed. 43 | //#include "ErrorStatus.h" 44 | //#include "RingBuffer.h" 45 | //#include "UART_DMA_Idle_Circular_Drv_STM32.h" 46 | //#include "StringManip.h" 47 | //#include "TimerCallback.h" 48 | 49 | #include "PollingRoutine.h" 50 | 51 | */ 52 | #ifndef __weak 53 | #define __weak __attribute__((weak)) 54 | #endif 55 | 56 | void PollingInit(void); 57 | void PollingRoutine(void); 58 | 59 | // uncomment if needed 60 | 61 | //void UART_ParseCommands(UART_DMA_Struct_t *msg); 62 | //void STM32_Ready(UART_DMA_Struct_t *msg); 63 | //int Version(char *msg, char *retStr) 64 | 65 | 66 | /* copy these 3 to main.h 67 | extern UART_HandleTypeDef huart2; 68 | 69 | extern UART_DMA_Struct_t uart2_msg; // uses USART2, but can be changed 70 | extern TimerCallbackStruct timerCallback; 71 | */ 72 | 73 | 74 | #endif /* INC_POLLINGROUTINE_H_ */ 75 | -------------------------------------------------------------------------------- /RingBuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | * @attention 4 | * 5 | * Copyright (c) 2025 Karl Yamashita 6 | * All rights reserved. 7 | * 8 | * This software is licensed under terms that can be found in the LICENSE file 9 | * in the root directory of this software component. 10 | * If no LICENSE file comes with this software, it is provided AS-IS. 11 | * 12 | ****************************************************************************** 13 | */ 14 | 15 | /* 16 | * RingBuffer.c 17 | * 18 | * Created on: Sep 18, 2019 19 | * Author: Karl 20 | * 21 | * 22 | */ 23 | 24 | #include "main.h" 25 | #include "ringBuffer.h" 26 | 27 | 28 | void RingBuff_Ptr_Reset(RING_BUFF_STRUCT *ptr) 29 | { 30 | ptr->index_IN = 0; 31 | ptr->index_OUT = 0; 32 | 33 | ptr->cnt_Handle = 0; 34 | ptr->cnt_OverFlow = 0; 35 | } 36 | 37 | int RingBuff_Ptr_Input(RING_BUFF_STRUCT *ptr, uint32_t bufferSize) 38 | { 39 | int status = 0; 40 | ptr->index_IN++; 41 | if (ptr->index_IN >= bufferSize) 42 | { 43 | ptr->index_IN = 0; 44 | status = 1; // roll over occurred 45 | } 46 | 47 | ptr->cnt_Handle++; 48 | if (ptr->index_IN == ptr->index_OUT) 49 | { 50 | ptr->cnt_OverFlow++; 51 | if (ptr->cnt_OverFlow > RING_BUFF_OVERFLOW_SIZE) 52 | ptr->cnt_OverFlow = 0; 53 | if (ptr->index_IN == 0) 54 | { 55 | ptr->index_OUT = bufferSize - 1; 56 | } 57 | else 58 | { 59 | ptr->index_OUT = ptr->index_IN - 1; 60 | } 61 | ptr->cnt_Handle = 1; 62 | } 63 | 64 | return status; 65 | } 66 | 67 | int RingBuff_Ptr_Output(RING_BUFF_STRUCT *ptr, uint32_t bufferSize) 68 | { 69 | int status = 0; 70 | 71 | if (ptr->cnt_Handle) 72 | { 73 | ptr->index_OUT++; 74 | if (ptr->index_OUT >= bufferSize) 75 | { 76 | ptr->index_OUT = 0; 77 | status = 1; // roll over occurred 78 | } 79 | ptr->cnt_Handle--; 80 | } 81 | 82 | return status; 83 | } 84 | -------------------------------------------------------------------------------- /Vehicle Drivers/ArbTextReqSetDisplayText.h: -------------------------------------------------------------------------------- 1 | #ifndef ARB_TEXT_REQ_SET_DISPLAY_TEXT_H 2 | #define ARB_TEXT_REQ_SET_DISPLAY_TEXT_H 3 | 4 | #define TEXT_SONG_NAME 1 5 | #define TEXT_ARTIST_NAME 2 6 | #define TEXT_RESERVED 3 7 | #define TEXT_CHANNEL_NAME 4 8 | #define TEXT_CATAGORY_NAME 5 9 | #define END_OF_TRANSMISSION 0x04 10 | #define NEW_LINE 0x0a 11 | 12 | #define DISPLAY_MAX_CHARACTERS_16 16 13 | #define DISPLAY_MAX_CHARACTERS_18 18 14 | 15 | typedef union ArbTextReqSetDisplayText{ 16 | struct { 17 | unsigned char byte[8]; 18 | }ByteArray; 19 | struct{ 20 | unsigned firstFrameActive:1;// this should be false 21 | unsigned targetDisplayIdentifier:4; 22 | unsigned requestingDeviceIdentifier:3; // bits start from bottom of struct going up from 7:0 23 | unsigned char frameSequenceNumber; // this will indicate what frame sequence we are at 24 | char characterString[6]; 25 | }Status; 26 | struct{ 27 | unsigned firstFrameActive:1; // this should be true 28 | unsigned targetDisplayIdentifier:4; 29 | unsigned requestingDeviceIdentifier:3; // bits start from bottom of struct going up from 7:0 30 | unsigned char frameSequenceNumber;// on first frame this will indicate how many frames total 31 | unsigned char characterType; // on first frame active byte2 is type of text (song, artist, catagory, etc) 32 | char characterString[5]; // only 5 characters if first frame active 33 | }CharacterType; 34 | }ArbTextReqSetDisplayText; 35 | 36 | typedef struct ArbTextReqSetStatus { 37 | uint8_t charPtr; 38 | uint8_t stringLength; 39 | uint8_t totalFrames; 40 | uint8_t totalFramesSent; 41 | }ArbTextReqSetStatus; 42 | 43 | bool ServiceArbitrationTextRequestSetDisplayTextXM(uint8_t *data); 44 | void SendArbTextReqSetDisplayText(ArbTextReqSetDisplayText *arbTextReqSetDisplayText); 45 | void SendArbTextReqSetDisplayTextCharacterType(uint8_t characterType, const char* mString); 46 | 47 | #endif // ARB_TEXT_REQ_SET_DISPLAY_TEXT_H 48 | -------------------------------------------------------------------------------- /Vehicle Drivers/CAN_TransceiverLSFT.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_CAN_TRANSCEIVER_LSFT 3 | #include "main.h" 4 | #include "CAN_TransceiverLSFT.h" 5 | #include "can.h" 6 | #include "gpio.h" 7 | #include "GPIO_Ports.h" 8 | 9 | #if defined USE_1_BUFFER // single CAN transceiver 10 | void InitCAN_Transceiver(void) { 11 | CAN_TransceiverSetMode(CAN_CONTROLLER1, CAN_NORMAL); 12 | hcan1.Instance = CAN1; 13 | HAL_CAN_MspInit(&hcan1); 14 | } 15 | 16 | void CAN_TransceiverSleep(void) { 17 | CAN_TransceiverSetMode(CAN_CONTROLLER1, CAN_SLEEP); 18 | } 19 | 20 | void CAN_TransceiverSetMode(unsigned char CAN_Controller, unsigned char mode) { 21 | if(mode) { 22 | PortB_Off(CAN_RS_Pin); // low = normal 23 | } else { 24 | PortB_On(CAN_RS_Pin); // high = sleep 25 | } 26 | } 27 | #endif // USE_1_BUFFERS 28 | 29 | #if defined USE_2_BUFFERS // dual CAN transceiver 30 | void InitDualCanTransceiver(void) { 31 | CAN_DualTransceiverSetMode(CAN_CONTROLLER1, CAN_NORMAL); 32 | CAN_DualTransceiverSetMode(CAN_CONTROLLER2, CAN_NORMAL); 33 | 34 | hcan1.Instance = CAN1; 35 | HAL_CAN_MspInit(&hcan1); 36 | hcan2.Instance = CAN2; 37 | HAL_CAN_MspInit(&hcan2); 38 | } 39 | 40 | void DualCanTransceiverSleep(void) { 41 | CAN_DualTransceiverSetMode(CAN_CONTROLLER1, CAN_SLEEP); 42 | CAN_DualTransceiverSetMode(CAN_CONTROLLER2, CAN_SLEEP); 43 | } 44 | 45 | void CAN_DualTransceiverSetMode(unsigned char CAN_Controller, unsigned char mode) { 46 | if(CAN_Controller == CAN_CONTROLLER1) { 47 | if(mode == CAN_NORMAL) { 48 | PortB_Off(CAN_RS_Pin); // low = normal 49 | } else { 50 | PortB_On(CAN_RS_Pin); // high = sleep 51 | } 52 | } else if(CAN_Controller == CAN_CONTROLLER2) { 53 | if(mode == CAN_NORMAL) { 54 | PortB_Off(CAN_RS_Pin); // low = normal 55 | } else { 56 | PortB_On(CAN_RS_Pin); // high = sleep 57 | } 58 | } 59 | } 60 | #endif // CAN2 61 | 62 | 63 | #endif // USE_CAN_TRANSCEIVER_LSFT 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /Vehicle Drivers/ArbTextDisplayLineAttributes.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_ARB_TEXT_DISPLAY_LINE_ATTRIBUTES 3 | 4 | #include "main.h" 5 | #include "ArbTextDisplayLineAttributes.h" 6 | #include "GMLAN_Defines.h" 7 | 8 | 9 | uint8_t arbTextDisplayLineAttributesHead = 0; 10 | uint8_t arbTextDisplayLineAttributesIPC = 0; 11 | uint8_t arbTextDisplayLineAttributesRSE = 0; 12 | 13 | 14 | void ServiceArbTextDisplayLineAttributes(uint8_t *data) { 15 | // todo find the line attributes 16 | uint8_t displayDeviceIdentifier = 0; 17 | displayDeviceIdentifier = data[0] >> 4; 18 | if(displayDeviceIdentifier == INFOTAINMENT_DISPLAY) { 19 | arbTextDisplayLineAttributesHead = data[1]; 20 | } else if(displayDeviceIdentifier == CLUSTER_DISPLAY) { 21 | arbTextDisplayLineAttributesIPC = data[1]; 22 | } else if (displayDeviceIdentifier == REAR_SEAT_DISPLAY) { 23 | arbTextDisplayLineAttributesRSE = data[1]; 24 | } 25 | } 26 | 27 | // 28 | // 0x1A = MP3 single line radio 29 | // 0x12 = IPC 30 | // 0x10 = Navigation radio 31 | // 0x90 = RSE 32 | uint8_t GetArbTextDisplayLineAttributesHead(void) { 33 | if(arbTextDisplayLineAttributesHead != 16 || arbTextDisplayLineAttributesHead != 18 || arbTextDisplayLineAttributesHead != 26) { 34 | arbTextDisplayLineAttributesHead = 16; 35 | } 36 | return arbTextDisplayLineAttributesHead; 37 | } 38 | 39 | uint8_t GetArbTextDisplayLineAttributesIPC(void) { 40 | if(arbTextDisplayLineAttributesIPC != 16 || arbTextDisplayLineAttributesIPC != 18 || arbTextDisplayLineAttributesHead != 26) { 41 | arbTextDisplayLineAttributesIPC = 16; 42 | } 43 | return arbTextDisplayLineAttributesIPC; 44 | } 45 | 46 | uint8_t GetArbTextDisplayLineAttributesRSE(void) { 47 | if(arbTextDisplayLineAttributesRSE != 16 || arbTextDisplayLineAttributesRSE != 18 || arbTextDisplayLineAttributesHead != 26) { 48 | arbTextDisplayLineAttributesRSE = 16; 49 | } 50 | return arbTextDisplayLineAttributesRSE; 51 | } 52 | 53 | #endif // USE_ARB_TEXT_DISPLAY_LINE_ATTRIBUTES 54 | 55 | -------------------------------------------------------------------------------- /Vehicle Drivers/SWC_SendDelayed.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_SWC_SEND_DELAYED 3 | #include "main.h" 4 | #include "SWC_SendDelayed.h" 5 | #include "RingBuff.h" 6 | #include "mTimers.h" 7 | #include "SWC.h" 8 | 9 | /* 10 | This section is used to send delayed SWC command 11 | */ 12 | #define MAX_SWC_STRUCTURE 4 13 | SWC_Structure swc_structure[MAX_SWC_STRUCTURE]; // buffer to hold command and delay value 14 | RING_BUFF_INFO swc_StructurePtr; 15 | 16 | uint8_t swcSendDelayTimer = 0; // timer instance 17 | 18 | /* 19 | function: Add SWC command with delay value to buffer 20 | input: The command and delay in milliseconds 21 | output: none 22 | */ 23 | void AddSWC_CommandToBufferCAN1(uint8_t command, uint32_t delay) { 24 | if(swcSendDelayTimer == 0) { 25 | swcSendDelayTimer = CreateTimer(); 26 | } 27 | swc_structure[swc_StructurePtr.iIndexIN].command = command; 28 | swc_structure[swc_StructurePtr.iIndexIN].delay = delay; // the delay before sending the SWC message 29 | if(swc_StructurePtr.iCnt_Handle == 0) { 30 | // buffer empty so reset timer for first command 31 | SetTimer(swcSendDelayTimer, 0); // clear timer 32 | } 33 | DRV_RingBuffPtr__Input(&swc_StructurePtr, MAX_SWC_STRUCTURE); // increment input buffer ptr 34 | } 35 | 36 | 37 | /* 38 | function: Check if time is reached then call SendSWC_Command_CAN1() function to place SWC command in Tx buffer 39 | input: none 40 | output: none 41 | */ 42 | // this needs to be called in polling routine 43 | void CheckDelayedSWC_CAN1(void) { 44 | if(swc_StructurePtr.iCnt_Handle){ // continue if there is a pending swc command to be sent 45 | if(GetTimer(swcSendDelayTimer) >= swc_structure[swc_StructurePtr.iIndexOUT].delay) { 46 | SetTimer(swcSendDelayTimer, 0); // clear timer for next swc command 47 | SendSWC_Command_CAN1(swc_structure[swc_StructurePtr.iIndexOUT].command); 48 | DRV_RingBuffPtr__Output(&swc_StructurePtr, MAX_SWC_STRUCTURE); // increment output buffer ptr 49 | } 50 | } 51 | } 52 | #endif // USE_SWC_SEND_DELAYED 53 | 54 | -------------------------------------------------------------------------------- /Vehicle Drivers/CAN_bufferV3.c: -------------------------------------------------------------------------------- 1 | // by Karl Yamashita September 2017 2 | 3 | #include "main.h" 4 | 5 | /* 6 | * Description: Increment pointer for rx buffer 7 | * 8 | */ 9 | void CAN_IncRxBuffer(CanMsg_Struct *msg) 10 | { 11 | RingBuff_Ptr_Input(&msg->rx.ptr, msg->rx.msgQueueSize); 12 | } 13 | 14 | 15 | /* 16 | * Description: Copies rxMsg to canMsg if message available. Needs to be called from polling routine 17 | * Input: The rxMsg queue. 18 | * Output: The canMsg that has the copy of the rxMsg queue 19 | * Return: 1 if message available, else 0 for no message 20 | */ 21 | int CAN_MsgAvailable(CanMsg_Struct *msg) 22 | { 23 | if(msg->rx.ptr.cnt_Handle) 24 | { 25 | msg->rx.msgToParse = &msg->rx.queue[msg->rx.ptr.index_OUT]; 26 | 27 | RingBuff_Ptr_Output(&msg->rx.ptr, msg->rx.msgQueueSize); 28 | return 1; // msgToParse points to msg 29 | } 30 | 31 | return 0; // no msg 32 | } 33 | 34 | 35 | /* 36 | * Description: Add message to Tx buffer 37 | * 38 | */ 39 | void CAN_AddTxBuffer(CanMsg_Struct *msg, CanTx *canMsg) 40 | { 41 | memcpy(&msg->tx.queue[msg->tx.ptr.index_IN].header, &canMsg->header, sizeof(canMsg->header)); 42 | memcpy(&msg->tx.queue[msg->tx.ptr.index_IN].data, &canMsg->data, sizeof(canMsg->data)); 43 | RingBuff_Ptr_Input(&msg->tx.ptr, msg->tx.msgQueueSize); // increment input buffer ptr 44 | } 45 | 46 | /* 47 | * Description: Check for new Tx CAN message and add to HAL_CAN_AddTxMessage. Called from polling routine. 48 | * Input: The CAN data structure to send. 49 | * 50 | */ 51 | void CAN_SendTxMessage(CanMsg_Struct *msg) 52 | { 53 | uint32_t CAN_Tx_Mailboxes; // not used but needed as an argument 54 | CanTx *ptr; 55 | 56 | if(msg->tx.ptr.cnt_Handle) // send available message 57 | { 58 | ptr = &msg->tx.queue[msg->tx.ptr.index_OUT]; 59 | 60 | if(HAL_CAN_AddTxMessage(msg->hcan, &ptr->header, ptr->data, &CAN_Tx_Mailboxes) == HAL_OK) 61 | { 62 | RingBuff_Ptr_Output(&msg->tx.ptr, msg->tx.msgQueueSize); // increment output buffer ptr 63 | } 64 | } 65 | } 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /UART_Handler_STM32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * UART_Handler.c 3 | * 4 | * Created on: Jul 21, 2023 5 | * Author: karl.yamashita 6 | */ 7 | 8 | 9 | 10 | #include "main.h" 11 | 12 | extern UartBufferStruct uart2; 13 | 14 | /* 15 | * Description: Enables the HAL_UART_Receive_IT interrupt. Call before main while loop and in HAL_UART_RxCpltCallback 16 | */ 17 | void UART_EnableRxInterrupt(UartBufferStruct *msg) 18 | { 19 | msg->rx.HAL_Status = HAL_UART_Receive_IT(msg->huart, &msg->rx.irqByte, 1); 20 | } 21 | 22 | /* 23 | * Description: If error flag then call UART_EnableRxInterrupt. Call from main while loop. 24 | * 25 | */ 26 | void UART_CheckRxIntError(UartBufferStruct *msg) 27 | { 28 | if(msg->rx.HAL_Status != HAL_OK) 29 | { 30 | UART_EnableRxInterrupt(msg); 31 | } 32 | } 33 | 34 | /* 35 | * Description: Transmit any available messages. 36 | */ 37 | int UART_TxMessage_IT(UartBufferStruct *msg) 38 | { 39 | int status = 0; 40 | UartDataStruct *ptr; 41 | 42 | if(msg->tx.ptr.cnt_Handle) 43 | { 44 | ptr = &msg->tx.queue[msg->tx.ptr.index_OUT]; 45 | 46 | if(HAL_UART_Transmit_IT(msg->huart, ptr->data, ptr->size) == HAL_OK) 47 | { 48 | RingBuff_Ptr_Output(&msg->tx.ptr, msg->tx.queueSize); 49 | } 50 | } 51 | 52 | return status; 53 | } 54 | 55 | 56 | // Example callback that need to be created, usually in pollingroutine 57 | 58 | /* 59 | 60 | void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) 61 | { 62 | if(huart == uart2.huart) 63 | { 64 | UART_AddByteToBuffer(&uart2); 65 | UART_EnableRxInterrupt(&uart2); 66 | } 67 | } 68 | 69 | 70 | void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) 71 | { 72 | if(huart == uart2.huart) 73 | { 74 | UART_TxMessage_IT(&uart2); // transmit more if queue is not empty 75 | } 76 | } 77 | 78 | // example create uart variable 79 | UartBufferStruct uart2 = 80 | { 81 | .huart = &huart2, 82 | .rx.queueSize = UART_RX_MESSAGE_QUEUE_SIZE, 83 | .tx.queueSize = UART_TX_MESSAGE_QUEUE_SIZE, 84 | .rx.uartType = UART_ASCII, 85 | .rx.irqByte = 0 86 | }; 87 | 88 | 89 | */ 90 | -------------------------------------------------------------------------------- /I2C_GenericHandler_STM32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * I2C_GenericHandler.h 3 | * 4 | * Created on: Apr 24, 2024 5 | * Author: karl.yamashita 6 | */ 7 | 8 | #ifndef INC_I2C_GENERICHANDLER_STM32_H_ 9 | #define INC_I2C_GENERICHANDLER_STM32_H_ 10 | 11 | 12 | enum TransferType_enum 13 | { 14 | I2C_POLLING, 15 | I2C_INTERRUPT, 16 | I2C_DMA 17 | }; 18 | 19 | 20 | #ifdef HAL_MODULE_ENABLED // STM32 21 | typedef struct 22 | { 23 | uint32_t pin; 24 | GPIO_TypeDef *port; // port base 25 | }GPIO_CS_t; // chip select 26 | #endif 27 | 28 | #ifndef XMEGA 29 | typedef struct __I2C_GenericDef_ // Microchip Studio compiler doesn't work with __I2C_GenericDef_ 30 | #else 31 | typedef struct 32 | #endif 33 | { 34 | #ifdef XMEGA 35 | TWI_t *twi_t; 36 | #endif 37 | #ifdef HAL_MODULE_ENABLED // STM32 38 | I2C_HandleTypeDef *i2c_instance; 39 | #endif 40 | #ifdef TARGET_IS_TM4C123_RB1 41 | uint32_t i2c_base; 42 | #endif 43 | 44 | uint8_t deviceAddr; // the slave address of device 45 | uint8_t *dataPtr; // pointer to data array 46 | uint8_t registerAddr[2]; // 8 or 16 bit address 47 | uint32_t dataSize; 48 | uint32_t regSize; // the size of the registerAddr, 1 or 2 bytes 49 | uint32_t timeout; // typically for STM32 that uses HAL timeout 50 | uint32_t transferType; // I2C_POLLING, I2C_INTERRUPT, I2C_DMA 51 | // TODO - define CS for TI and XMEGA 52 | #ifdef HAL_MODULE_ENABLED // STM32 53 | GPIO_CS_t cs; // chip select 54 | #endif 55 | #ifndef XMEGA // all but XMEGA can use these callbacks 56 | void (*RxISR)(struct __I2C_GenericDef_ *i2c); 57 | void (*TxISR)(struct __I2C_GenericDef_ *i2c); // probably not needed but here nonetheless 58 | #endif 59 | char *cmdPtr; // pointer to copy of command message 60 | }__attribute__((aligned(32))) I2C_GenericDef; 61 | 62 | 63 | int I2C_Master_Receive_Generic_Method(I2C_GenericDef *i2c); 64 | int I2C_Master_Transmit_Generic_Method(I2C_GenericDef *i2c); 65 | int I2C_Mem_Read_Generic_Method(I2C_GenericDef *i2c); 66 | int I2C_Mem_Write_Generic_Method(I2C_GenericDef *i2c); 67 | 68 | 69 | 70 | 71 | #endif /* INC_I2C_GENERICHANDLER_STM32_H_ */ 72 | -------------------------------------------------------------------------------- /USB_CAN_Convert.h: -------------------------------------------------------------------------------- 1 | /* 2 | ****************************************************************************** 3 | * @attention 4 | * 5 | * Copyright (c) 2025 Karl Yamashita 6 | * All rights reserved. 7 | * 8 | * This software is licensed under terms that can be found in the LICENSE file 9 | * in the root directory of this software component. 10 | * If no LICENSE file comes with this software, it is provided AS-IS. 11 | * 12 | ****************************************************************************** 13 | */ 14 | 15 | #ifndef USB_CAN_CONVERT_H 16 | #define USB_CAN_CONVERT_H 17 | 18 | 19 | // Node defines 20 | #define CAN1_NODE 0 21 | #define CAN2_NODE 1 22 | #define SWCAN1_NODE 2 23 | #define LSFTCAN1_NODE 3 24 | #define LIN1_NODE 4 25 | #define ETH1_NODE 5 26 | #define SWCAN2_NODE 6 27 | #define LSFTCAN2_NODE 7 28 | 29 | #define CAN_STD_ID 0x00 30 | #define CAN_EXT_ID 0x04 31 | 32 | #define CAN_DATA_SIZE 17 33 | 34 | // the structure sent by the PC. 35 | typedef union UsbCanStruct { 36 | struct { 37 | uint8_t data[CAN_DATA_SIZE]; 38 | }array; 39 | struct { 40 | uint32_t IDE:8; // ide, STD or EXT 41 | uint32_t RTR:8;// rtr 42 | uint32_t na:8; // node 43 | uint32_t :8; // reserved 44 | 45 | uint32_t ArbID; // ArbID 46 | uint32_t DLC:8; // dlc 47 | uint8_t array[8]; // 8 data bytes 48 | }dataBytes; 49 | struct { 50 | uint32_t IDE:8; // byte1 51 | uint32_t RTR:1; // RTR, ERR, byte2 52 | uint32_t Err:1; // not implemented 53 | uint32_t :6; 54 | uint32_t Node:4; // byte3, see Node defines 55 | uint32_t :4; 56 | uint32_t :8; // reserved 57 | 58 | // ArbID byte4:7 59 | uint32_t ArbId; // holds 11 and 29 bit ID. This has to align within 32bit address 60 | // 61 | uint32_t DLC:8; // byte8 62 | uint8_t Byte1; // byte9 63 | uint8_t Byte2; 64 | uint8_t Byte3; 65 | uint8_t Byte4; 66 | uint8_t Byte5; 67 | uint8_t Byte6; 68 | uint8_t Byte7; 69 | uint8_t Byte8; // byte16 70 | }msgBytes; 71 | }UsbCanStruct; 72 | 73 | void USB_to_CAN_Send(CAN_MsgStruct *msg, uint8_t *data); 74 | void CAN_to_USB_Send(CAN_MsgStruct *msg, uint8_t node); 75 | 76 | #endif // USB_CAN_CONVERT_H 77 | 78 | -------------------------------------------------------------------------------- /Vehicle Drivers/CAN_Autobaud.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #if defined USE_CAN_AUTOBAUD 3 | #include "main.h" 4 | #include "CAN_Autobaud.h" 5 | #include "can.h" 6 | #include "can_buffer.h" 7 | #include "ringBuff.h" 8 | 9 | 10 | extern RING_BUFF_INFO RxMessagePtr1; 11 | extern CanRxMsgTypeDef RxMessageBuffer1[CAN_MAX_RX_BUFF]; 12 | 13 | const Bitrate_stm bitrate_stm[COUNT_BITRATE]= { 14 | // PRESCal BS1 BS2 15 | { 6 , CAN_BS1_8TQ, CAN_BS2_3TQ} // 500kbit S6 16 | , { 12 , CAN_BS1_8TQ, CAN_BS2_3TQ} // 250kbit S5 17 | , { 24 , CAN_BS1_8TQ, CAN_BS2_3TQ} // 125kbit S4 18 | , { 30 , CAN_BS1_8TQ, CAN_BS2_3TQ} // 100kbit S3 19 | , { 36 , CAN_BS1_8TQ, CAN_BS2_3TQ} // 83kbit S9 20 | , { 90 , CAN_BS1_8TQ, CAN_BS2_3TQ} // 33kbit 21 | }; 22 | 23 | /* 24 | Auto detect the CAN bus baudrate 25 | */ 26 | int8_t CAN_Autobaud(void) { 27 | int8_t baudRate = -1; 28 | static uint8_t mode = 0, baudRateCount = 0; 29 | Bitrate_stm bitrate; 30 | 31 | while(1) { 32 | switch(mode) { 33 | case 0: // set new baudrate 34 | bitrate = bitrate_stm[baudRateCount]; 35 | // MX_CAN1_SetBaudRate(&bitrate); 36 | break; 37 | case 1: 38 | if(RxMessagePtr1.iCnt_Handle) {// check for messages 39 | if(RxMessageBuffer1[RxMessagePtr1.iIndexOUT].IDE == CAN_ID_STD) { // std id 40 | switch(RxMessageBuffer1[RxMessagePtr1.iIndexOUT].StdId) { 41 | case 0x000: // power mode for 83.333kbs 42 | case 0x20B: // newer 83.333kbs 43 | 44 | break; 45 | case 0x122: // power mode for 125kbs 46 | 47 | break; 48 | default: 49 | break; 50 | } 51 | } 52 | DRV_RingBuffPtr__Output(&RxMessagePtr1, CAN_MAX_RX_BUFF); // increment output buffer ptr 53 | } 54 | break; 55 | case 2: 56 | 57 | break; 58 | } 59 | if(1) { 60 | break; 61 | } 62 | } 63 | 64 | return baudRate; 65 | } 66 | 67 | #endif // USE_CAN_AUTOBAUD 68 | -------------------------------------------------------------------------------- /UART_Handler_dsPIC33.c: -------------------------------------------------------------------------------- 1 | /* 2 | * UART_Handler.c 3 | * 4 | * Created on: Jul 21, 2023 5 | * Author: karl.yamashita 6 | */ 7 | 8 | 9 | 10 | #include "main.h" 11 | 12 | 13 | 14 | UartBufferStruct uart1_msg = 15 | { 16 | .instance = UART_PORT_1, 17 | .rx.uartType = UART_ASCII 18 | }; 19 | 20 | UartBufferStruct uart2_msg = 21 | { 22 | .instance = UART_PORT_2, 23 | .rx.uartType = UART_ASCII 24 | }; 25 | 26 | 27 | /* 28 | * Microchip default callback 29 | * 30 | */ 31 | // UART1_Receive_CallBack for Classic 32 | void UART1_RxCompleteCallback(void) 33 | { 34 | uart1_msg.rx.irqByte = (uint8_t)U1RXREG; 35 | UART_AddByteToBuffer(&uart1_msg); 36 | } 37 | 38 | // UART2_Receive_CallBack for Classic 39 | void UART2_RxCompleteCallback(void) 40 | { 41 | uart2_msg.rx.irqByte = (uint8_t)U2RXREG; 42 | UART_AddByteToBuffer(&uart2_msg); 43 | } 44 | 45 | 46 | /* 47 | * Description: Sends string 48 | * 49 | * Input: Character buffer structure. The structure holds the UART base and the char array. 50 | * Output: HAL status 51 | */ 52 | int UART_TxMessage(UartBufferStruct *msg) 53 | { 54 | uint16_t size = 0; 55 | uint8_t i = 0; 56 | uint8_t uartPort; 57 | uint8_t *ptr; 58 | 59 | if(msg->tx.ptr.cnt_Handle) 60 | { 61 | ptr = msg->tx.queue[msg->tx.ptr.index_OUT].data; 62 | size = msg->tx.queue[msg->tx.ptr.index_OUT].size; 63 | uartPort = msg->instance; 64 | 65 | while(size) 66 | { 67 | if(uartPort == 1) 68 | { 69 | if(!(U1STAHbits.UTXBF == 1)) 70 | { 71 | U1TXREG = msg->tx.queue[msg->tx.ptr.index_OUT].data[i]; 72 | size--; 73 | i++; 74 | } 75 | } 76 | else if(uartPort == 2) 77 | { 78 | if(!(U2STAHbits.UTXBF == 1)) 79 | { 80 | U2TXREG = msg->tx.queue[msg->tx.ptr.index_OUT].data[i]; 81 | size--; 82 | i++; 83 | } 84 | } 85 | } 86 | 87 | RingBuff_Ptr_Output(&msg->tx.ptr, UART_TX_MESSAGE_QUEUE_SIZE); 88 | } 89 | return NO_ERROR; 90 | } 91 | 92 | -------------------------------------------------------------------------------- /I2C_Generic_Handler_TM4C.h: -------------------------------------------------------------------------------- 1 | /* 2 | * File: I2C_Generic_Handler.h 3 | * Author: karl.yamashita 4 | * 5 | * Created on August 12, 2022, 12:30 PM 6 | */ 7 | 8 | #ifndef I2C_GENERIC_HANDLER_H 9 | #define I2C_GENERIC_HANDLER_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | 16 | enum TransferType_enum 17 | { 18 | I2C_POLLING, 19 | I2C_INTERRUPT, 20 | I2C_DMA 21 | }; 22 | 23 | 24 | #ifdef HAL_MODULE_ENABLED // STM32 25 | typedef struct 26 | { 27 | uint32_t pin; 28 | GPIO_TypeDef *port; // port base 29 | }GPIO_CS_t; // chip select 30 | #endif 31 | 32 | #ifndef XMEGA 33 | typedef struct __I2C_GenericDef_ // Microchip Studio compiler doesn't work with __I2C_GenericDef_ 34 | #else 35 | typedef struct 36 | #endif 37 | { 38 | #ifdef XMEGA 39 | TWI_t *twi_t; 40 | #endif 41 | #ifdef HAL_MODULE_ENABLED // STM32 42 | I2C_HandleTypeDef *i2c_instance; 43 | #endif 44 | #ifdef TARGET_IS_TM4C123_RB1 45 | uint32_t i2c_base; 46 | #endif 47 | 48 | uint8_t deviceAddr; // the slave address of device 49 | uint8_t *dataPtr; // pointer to data array 50 | uint8_t registerAddr[2]; // 8 or 16 bit address 51 | uint32_t dataSize; 52 | RING_BUFF_STRUCT dataIdxPtr; 53 | uint32_t regSize; // the size of the registerAddr, 1 or 2 bytes 54 | uint32_t timeout; // typically for STM32 that uses HAL timeout 55 | uint32_t transferType; // I2C_POLLING, I2C_INTERRUPT, I2C_DMA 56 | // TODO - define CS for TI and XMEGA 57 | #ifdef HAL_MODULE_ENABLED // STM32 58 | GPIO_CS_t cs; // chip select 59 | #endif 60 | #ifndef XMEGA // all but XMEGA can use these callbacks 61 | void (*RxISR)(struct __I2C_GenericDef_ *i2c); 62 | void (*TxISR)(struct __I2C_GenericDef_ *i2c); // probably not needed but here nonetheless 63 | #endif 64 | char *cmdPtr; // pointer to copy of command message 65 | }__attribute__((aligned(32))) I2C_GenericDef; 66 | 67 | 68 | int I2C_Master_Receive_Generic_Method(I2C_GenericDef *i2c); 69 | int I2C_Master_Transmit_Generic_Method(I2C_GenericDef *i2c); 70 | int I2C_Mem_Read_Generic_Method(I2C_GenericDef *i2c); 71 | int I2C_Mem_Write_Generic_Method(I2C_GenericDef *i2c); 72 | 73 | 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif /* I2C_GENERIC_HANDLER_H */ 80 | 81 | -------------------------------------------------------------------------------- /Radio Drivers/Clarion.c: -------------------------------------------------------------------------------- 1 | #include "LSP.h" 2 | #ifdef USE_CLARION 3 | #include "main.h" 4 | #include "RadioFunctions.h" 5 | #include "Clarion.h" 6 | #include "gpio_ports.h" 7 | 8 | void ClarionStartBit(void){ 9 | PortB_Off(SWC_Pin); // pull low 10 | // delay 9 ms 11 | PortB_On(SWC_Pin); // set high 12 | // delay 4.5 ms 13 | } 14 | 15 | void ClarionBit(unsigned char bit){ 16 | PortB_Off(SWC_Pin); // pull low 17 | // delay 560us 18 | PortB_On(SWC_Pin); // set high 19 | if(bit == 0){ 20 | // delay 560us 21 | } else { 22 | // delay 1.69ms 23 | } 24 | } 25 | 26 | void ClarionSendCommand(unsigned char command){ 27 | unsigned char i; 28 | for(i = 0; i < 8; i++){ 29 | if((command & 0x01) == 1) 30 | { 31 | ClarionBit(1); 32 | } 33 | else 34 | { 35 | ClarionBit(0); 36 | } 37 | command >>= 1; 38 | } 39 | } 40 | 41 | void Clarion(unsigned char command, unsigned int customCode2Flag){ 42 | unsigned int customeCode = CLARION_CUSTOM_CODE; 43 | if(customCode2Flag) { 44 | customeCode = CLARION_CUSTOM_CODE_2; 45 | } 46 | ClarionStartBit(); 47 | ClarionSendCommand(customeCode >> 8); // send custom high byte first 48 | ClarionSendCommand( (unsigned char) customeCode); // send custom low byte 49 | ClarionSendCommand(command); // send command 50 | command = ~command;// invert command 51 | ClarionSendCommand(command); // send inverted command 52 | ClarionBit(1); // need to send for older radios 53 | } 54 | 55 | void ClarionCommand(unsigned char command) { 56 | switch(command){ 57 | case 0: 58 | break; 59 | case 1:Clarion(CLARION_VOLUME_UP, NULL); 60 | break; 61 | case 2:Clarion(CLARION_VOLUME_DOWN, NULL); 62 | break; 63 | case 3:Clarion(CLARION_MUTE, NULL); 64 | break; 65 | case 4:Clarion(CLARION_SOURCE, NULL); 66 | break; 67 | case 5:Clarion(CLARION_TRACK_UP, NULL); 68 | break; 69 | case 6:Clarion(CLARION_TRACK_DOWN, NULL); 70 | break; 71 | case 7:Clarion(CLARION_BAND, NULL); 72 | break; 73 | case 8:Clarion(CLARION_SEND_END, NULL); 74 | break; 75 | case 9:Clarion(CLARION_SEND, CLARION_CUSTOM_CODE_TRUE); 76 | break; 77 | case 10:Clarion(CLARION_END, CLARION_CUSTOM_CODE_TRUE); 78 | break; 79 | default: 80 | break; 81 | } 82 | } 83 | #endif // USE_CLARION 84 | 85 | 86 | --------------------------------------------------------------------------------