diff --git a/CMakeLists.txt b/CMakeLists.txt index a7cd95e..7c31169 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,16 +109,16 @@ message("${BoldBlue}") message("+-------------------------------+") message("Adding Header Directories") message("+-------------------------------+") -message("|-->For Drivers") -createHeaderDirList("${DRIVERS_DIR}" "${DRIVERS_LIST}" "DRIVERS_HEADERS_DIR") +message("|-->For System") +createHeaderDirList("${SYSTEM_DIR}" "${SYSTEM_LIST}" "SYSTEM_HEADERS_DIR") message("${BoldBlue}|-->For Peripherals") createHeaderDirList("${PERIPHERALS_DIR}" "${PERIPHERALS_LIST}" "PERIPHERALS_HEADERS_DIR") +message("${BoldBlue}|-->For Drivers") +createHeaderDirList("${DRIVERS_DIR}" "${DRIVERS_LIST}" "DRIVERS_HEADERS_DIR") message("${BoldBlue}|-->For Libraries") createHeaderDirList("${LIBRARIES_DIR}" "${LIBRARIES_LIST}" "LIBRARIES_HEADERS_DIR") message("${BoldBlue}|-->For Project") checkDirectories("${PROJECT_HEADERS_DIR}") -message("${BoldBlue}|-->For System") -createHeaderDirList("${SYSTEM_DIR}" "${SYSTEM_LIST}" "SYSTEM_HEADERS_DIR") message("${BoldBlue}+-------------------------------+${ColourReset}") set (COMMON_HEADERS ${CSL_HEADERS_DIR} @@ -135,23 +135,28 @@ message("${BoldBlue}") message("+-------------------------------+") message("Making Submolues") message("+-------------------------------+") -message("|-->For Drivers") -makeSubmodules("${DRIVERS_DIR}" "${DRIVERS_LIST}" "DRIVER_LIBS") +message("|-->For System") +makeSubmodules("${SYSTEM_DIR}" "${SYSTEM_LIST}" "SYSTEM_LIBS") message("${BoldBlue}|-->For Peripherals") makeSubmodules("${PERIPHERALS_DIR}" "${PERIPHERALS_LIST}" "PERIPHERAL_LIBS") +message("${BoldBlue}|-->For Drivers") +makeSubmodules("${DRIVERS_DIR}" "${DRIVERS_LIST}" "DRIVER_LIBS") message("${BoldBlue}|-->For Libraries") makeSubmodules("${LIBRARIES_DIR}" "${LIBRARIES_LIST}" "LIBRARIES_LIBS") message("${BoldBlue}|-->For Project") makeSubmodules("${PROJECT_DIR}" "${PROJECT_SOURCES_DIR_LIST}" "PROJECT_LIBS") -message("${BoldBlue}|-->For System") -makeSubmodules("${SYSTEM_DIR}" "${SYSTEM_LIST}" "SYSTEM_LIBS") message("${BoldBlue}+-------------------------------+${ColourReset}") #################################################################################################### # Stick All the libraries together, only for code redability futher down. #################################################################################################### -foreach(X IN LISTS STARTUP_UCODE PROJECT_LIBS PERIPHERAL_LIBS DRIVER_LIBS LIBRARIES_LIBS SYSTEM_LIBS) +foreach(X IN LISTS STARTUP_UCODE + PROJECT_LIBS + PERIPHERAL_LIBS + DRIVER_LIBS + LIBRARIES_LIBS + SYSTEM_LIBS) list(APPEND GENERATED_LIBRARIES ${X}) endforeach() diff --git a/env/cmake_core/cmakeCore.cmake b/env/cmake_core/cmakeCore.cmake index 7509b6f..46c1ba9 100755 --- a/env/cmake_core/cmakeCore.cmake +++ b/env/cmake_core/cmakeCore.cmake @@ -35,48 +35,120 @@ function(createHeaderDirList _directory _list _headersList) set(${_headersList} ${_newheaderDirList} PARENT_SCOPE) endfunction() + +# This function searches for the given header file name (_alias) if it has benn included +# If it finds it it retursn the directory where the header is Located +# If it doesn't find a header it generates a fatal error +function(checkIfHeaderFileIncluded _alias _retDir) + set(_headerFound FALSE) + set(_headerDirFound) + foreach(_headerDir IN LISTS COMMON_HEADERS) + if(EXISTS ${_headerDir}/${alias}.h) + set(_headerFound TRUE) + set(_headerDirFound ${_headerDir}) + endif() + endforeach() + + if(_headerFound) + set(${_retDir} ${_headerDirFound}/${alias}.h PARENT_SCOPE) + else() + errorHFileNotFound(${_headerDirFound} ${_alias}) + endif() +endfunction() + +# This function searches for the given header file name (_alias) if it has benn included +# If it finds it it retursn the directory where the header is Located +# If it doesn't find a header it returns a Non Found Message +function(searchHeaderFile _alias _retDir) + set(_headerFound FALSE) + set(_headerDirFound) + foreach(_headerDir IN LISTS COMMON_HEADERS) + if(EXISTS ${_headerDir}/${alias}.h) + set(_headerFound TRUE) + set(_headerDirFound ${_headerDir}) + endif() + endforeach() + + if(_headerFound) + set(${_retDir} ${_headerDirFound}/${alias}.h PARENT_SCOPE) + else() + set(${_retDir} "Not Found" PARENT_SCOPE) + endif() +endfunction() + #################################################################################################### # SUBMODULE MANAGEMENT #################################################################################################### function(makeSubmodules _directory _aliasList _submoduleList) set(_newSubmoduleList) + set(_headerLoc) + #For each alias of element present on the list that have been given as argument foreach(alias IN LISTS _aliasList) - checkDirectory("${_directory}/${alias}") - if(EXISTS ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) - message("${BoldYellow} |-> Target Found : ${alias} ") - if(EXISTS ${_directory}/${alias}/${alias}.${PL}) - message(" |-> Imp source : ${CSL_SOURCES_DIR}/imp_${alias}.${PL}") + + checkDirectory("${_directory}/${alias}") # Does the directory exists (If not fatal error) + + #Does the given element has an implmenetation for a CSL + if(EXISTS ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) #If yes + message("${BoldCyan} |-> Target Found : ${alias} ${BoldYellow} ") + + checkIfHeaderFileIncluded("${alias}" "_headerLoc") #Every Implementation has to have a header (if not Fatal Error) + + #Does the given element has an predefined standart usage library + if(EXISTS ${_directory}/${alias}/${alias}.${PL}) # If yes then add this to the compiling list + message(" |-> Def Header : ${_headerLoc}") message(" |-> Lib Source : ${_directory}/${alias}/${alias}.${PL} ") + message(" |-> Imp source : ${CSL_SOURCES_DIR}/imp_${alias}.${PL}") + add_library(${alias}_submodule ${_directory}/${alias}/${alias}.${PL} ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) - else() + else() # If No than just compile the implmentation source + message(" |-> Def Header : ${_headerLoc}") message(" |-> Imp source : ${CSL_SOURCES_DIR}/imp_${alias}.${PL}") + add_library(${alias}_submodule ${CSL_SOURCES_DIR}/imp_${alias}.${PL}) endif() - message(" |-> Name : sub::${alias}") + + message(" |-> Name : sub::${alias}") + target_compile_options(${alias}_submodule PRIVATE ${MAIN_FLAGS}) target_compile_definitions(${alias}_submodule PRIVATE ${MAIN_DEFS}) target_include_directories(${alias}_submodule PUBLIC ${COMMON_HEADERS}) add_library(sub::${alias} ALIAS ${alias}_submodule) + + #Append the internal submodule list with the newly compiled element list(APPEND _newSubmoduleList sub::${alias}) - else() + + else() # Else, when the element has no implmentation for a CSL + #If the element has an source file if(EXISTS ${_directory}/${alias}/${alias}.${PL}) - message("${BoldYellow} |-> Target Found : ${alias} ") + searchHeaderFile("${alias}" "_headerLoc") #Searches if there is an Header (if not it will not generate any error) + message("${BoldCyan} |-> Target Found : ${alias} ${BoldYellow} ") + message(" |-> Header : ${_headerLoc}") message(" |-> Source : ${_directory}/${alias}/${alias}.${PL}") message(" |-> Name : sub::${alias}") + add_library(${alias}_submodule ${_directory}/${alias}/${alias}.${PL}) target_compile_options(${alias}_submodule PRIVATE ${MAIN_FLAGS}) target_compile_definitions(${alias}_submodule PRIVATE ${MAIN_DEFS}) target_include_directories(${alias}_submodule PUBLIC ${COMMON_HEADERS}) add_library(sub::${alias} ALIAS ${alias}_submodule) + + #Append the internal submodule list with the newly compiled element list(APPEND _newSubmoduleList sub::${alias}) - else() + + else() # When the element has no source file and is only a header. message("${BoldMagenta} |-> No Source file for target : ${alias}") message(" |-> Only headers will be added") endif() + endif() + endforeach() + message("${ColourReset}") + + #New submodule list with the names of the compiled elements set(${_submoduleList} ${_newSubmoduleList} PARENT_SCOPE) + endfunction() #################################################################################################### @@ -87,4 +159,3 @@ function(printList _txt _list) message("${_txt}${X}") endforeach() endfunction() - diff --git a/env/cmake_core/errorHandler.cmake b/env/cmake_core/errorHandler.cmake index 8a1340e..2f91ed8 100755 --- a/env/cmake_core/errorHandler.cmake +++ b/env/cmake_core/errorHandler.cmake @@ -15,7 +15,7 @@ function(errorOut) message("#########################################\n\n") endfunction() -function(errorDirNotFound) +function(errorDirNotFound _searchedDir) errorDetected() message(" |-->GIVEN DIRECTORY NOT FOUND") message(" |-> Given dir : ${DIR}") diff --git a/libraries/examples/autoInit/main.c b/libraries/examples/autoInit/main.c index 3f495a6..25a8bd3 100644 --- a/libraries/examples/autoInit/main.c +++ b/libraries/examples/autoInit/main.c @@ -1,33 +1,27 @@ #include "main.h" #include "delay.h" -#include "pin.h" #include "deviceSetup.h" -#include "uartComm.h" -#include "sensor.h" +#include "usart.h" +#include "ascii.h" +#include "timer.h" int main(int argc, char *argv[]) -{ +{ uint8_t i = 0; - - delayInitMs(8000000, 1000); // Clock Freq and Divider for ARM library + delayInitMs(8000000, 1000); // Clock Freq and Divider for ARM library + pinConfig(pinB3, output, pushPull, def_res, def_speed); pinConfig(pinA0, input, def_stage, pullDown, def_speed); setupInit(); // This is the sescond call of System init the assebly start code is calling it before the main. + + usartInit(usart2, pinA2, pinA15, 115200, eight, NO_PARITY_CTRL, noFlowControl); - uartCommInit(); - //blinks 10 times to indicate the sicsessfull init if the device - for(i = 0 ; i < 2 ; i++) { - delayMs(100); - pinToggle(pinB3); - delayMs(100); - } + //clears screen and send the wellcome messgae + print_Usart(usart2, ASCII_clear); + print_Usart(usart2, "Hello to our KED project\n\r"); - uartCommPrintWellcome(); - sensorActivate(1); - sensorActivate(0); - while(1) { delayMs(100); @@ -37,4 +31,3 @@ int main(int argc, char *argv[]) return 1; } - diff --git a/libraries/examples/autoInit/main.h b/libraries/examples/autoInit/main.h new file mode 100644 index 0000000..4a3e41b --- /dev/null +++ b/libraries/examples/autoInit/main.h @@ -0,0 +1,15 @@ +#ifndef MAIN_H +#define MAIN_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + + +#ifdef __cplusplus +} +#endif + +#endif /* MAIN_H */ diff --git a/libraries/examples/autoInit/projectDefinitions.cmake b/libraries/examples/autoInit/projectDefinitions.cmake index 5dadf91..dc8a7d9 100644 --- a/libraries/examples/autoInit/projectDefinitions.cmake +++ b/libraries/examples/autoInit/projectDefinitions.cmake @@ -4,7 +4,7 @@ # list() = List declaration "DON'T CHANGE" # PROJECT_HEADERS_DIR = Variable containing the listed direcotries "DON'T CHANCE # ${PROJECT_DIR} = Direcotry of the main project this is per default the current direcotry it is defined in ked/CMakeLists.txt -list(APPEND PROJECT_HEADERS_DIR ${PROJECT_DIR}/headers) +list(APPEND PROJECT_HEADERS_DIR ${PROJECT_DIR}) #Declaring sources directory for the project #To add a new directory @@ -12,10 +12,9 @@ list(APPEND PROJECT_HEADERS_DIR ${PROJECT_DIR}/headers) # list() = List declaration "DON'T CHANGE" # PROJECT_SOURCES_DIR = Variable containing the listed direcotries "DON'T CHANCE # ${PROJECT_DIR} = Direcotry of the main project this is per default the current direcotry it is defined in ked/CMakeLists.txt -list(APPEND PROJECT_SOURCES_DIR ${PROJECT_DIR}/src) -list(APPEND PROJECT_SOURCES_DIR ${PROJECT_DIR}/sensors) +list(APPEND PROJECT_SOURCES_DIR) #Declaring sources to be compiled for the project. #CMake will look in each previsouly declarec sources directory until to find this files. -set(PROJECT_SOURCES_DIR_LIST uartComm sensor) +set(PROJECT_SOURCES_DIR_LIST) diff --git a/libraries/examples/i2c_oled_display/main.c b/libraries/examples/i2c_oled_display/main.c index cc850f0..0309d28 100644 --- a/libraries/examples/i2c_oled_display/main.c +++ b/libraries/examples/i2c_oled_display/main.c @@ -15,7 +15,17 @@ int main(int argc, char *argv[]) uint8_t registerToRead = 0x00; uint8_t i2cRecieved = 0; uint8_t i2cData = 0xFF; - i2c_t i2c_1; + + i2c_t i2c_1 = { I2C_CH_1, /*!< The harware channel to be used */ + i2c_mode_master, /*!< Master Mode */ + 0x00, /*!< First and Main address of the device */ + 0x00, /*!< Second address if dual addresse mode is configured */ + i2c_address_count_single, /*!< Single address */ + i2c_address_size_7b, /*!< 10 or 7 bit address size */ + i2c_clk_speed_standart, /*!< Bus Speed: standart */ + i2c_clk_stretching_disable, /*!< Clock Streching disabeled */ + i2c_wake_disabled /*!< Wake up condition : None */ + }; delayInitMs(8000000, 1000); // Clock Freq and Divider for ARM library @@ -46,7 +56,7 @@ int main(int argc, char *argv[]) pinWrite(pinB3,0); - i2c_init(&i2c_1, I2C_CH_1, i2c_mode_master, 0x00,0x00, i2c_address_count_single, i2c_address_size_7b, i2c_clk_speed_standart, i2c_clk_stretching_disable, i2c_wake_disabled); + i2c_init(&i2c_1); slaveAddress = SSD1306_I2C_ADDRESS; registerToRead = 0x02; diff --git a/libraries/examples/i2c_oled_display/projectDefinitions.cmake b/libraries/examples/i2c_oled_display/projectDefinitions.cmake index ae3d0fd..dc8a7d9 100644 --- a/libraries/examples/i2c_oled_display/projectDefinitions.cmake +++ b/libraries/examples/i2c_oled_display/projectDefinitions.cmake @@ -12,9 +12,9 @@ list(APPEND PROJECT_HEADERS_DIR ${PROJECT_DIR}) # list() = List declaration "DON'T CHANGE" # PROJECT_SOURCES_DIR = Variable containing the listed direcotries "DON'T CHANCE # ${PROJECT_DIR} = Direcotry of the main project this is per default the current direcotry it is defined in ked/CMakeLists.txt -# list(APPEND PROJECT_SOURCES_DIR ${PROJECT_DIR}/src) +list(APPEND PROJECT_SOURCES_DIR) #Declaring sources to be compiled for the project. #CMake will look in each previsouly declarec sources directory until to find this files. -# set(PROJECT_SOURCES_DIR_LIST uartComm sensor) +set(PROJECT_SOURCES_DIR_LIST) diff --git a/libraries/examples/autoInit/headers/main.h b/libraries/examples/initWithConfig/headers/main.h similarity index 100% rename from libraries/examples/autoInit/headers/main.h rename to libraries/examples/initWithConfig/headers/main.h diff --git a/libraries/examples/autoInit/headers/uartComm.h b/libraries/examples/initWithConfig/headers/uartComm.h similarity index 100% rename from libraries/examples/autoInit/headers/uartComm.h rename to libraries/examples/initWithConfig/headers/uartComm.h diff --git a/libraries/examples/initWithConfig/main.c b/libraries/examples/initWithConfig/main.c new file mode 100644 index 0000000..3f495a6 --- /dev/null +++ b/libraries/examples/initWithConfig/main.c @@ -0,0 +1,40 @@ +#include "main.h" +#include "delay.h" +#include "pin.h" +#include "deviceSetup.h" +#include "uartComm.h" +#include "sensor.h" + +int main(int argc, char *argv[]) +{ + uint8_t i = 0; + + delayInitMs(8000000, 1000); // Clock Freq and Divider for ARM library + + pinConfig(pinB3, output, pushPull, def_res, def_speed); + pinConfig(pinA0, input, def_stage, pullDown, def_speed); + + setupInit(); // This is the sescond call of System init the assebly start code is calling it before the main. + + uartCommInit(); + //blinks 10 times to indicate the sicsessfull init if the device + for(i = 0 ; i < 2 ; i++) { + delayMs(100); + pinToggle(pinB3); + delayMs(100); + } + + uartCommPrintWellcome(); + sensorActivate(1); + sensorActivate(0); + + while(1) + { + delayMs(100); + pinToggle(pinB3); + delayMs(100); + } + + return 1; +} + diff --git a/libraries/examples/initWithConfig/projectDefinitions.cmake b/libraries/examples/initWithConfig/projectDefinitions.cmake new file mode 100644 index 0000000..5dadf91 --- /dev/null +++ b/libraries/examples/initWithConfig/projectDefinitions.cmake @@ -0,0 +1,21 @@ +#Declareing header directory for the project +#To add a new directory +# -> list(APPEND PROJECT_HEADERS_DIR ${PROJECT_DIR}/YOUR_DESIRED_DIRECTORY) +# list() = List declaration "DON'T CHANGE" +# PROJECT_HEADERS_DIR = Variable containing the listed direcotries "DON'T CHANCE +# ${PROJECT_DIR} = Direcotry of the main project this is per default the current direcotry it is defined in ked/CMakeLists.txt +list(APPEND PROJECT_HEADERS_DIR ${PROJECT_DIR}/headers) + +#Declaring sources directory for the project +#To add a new directory +# -> list(APPEND PROJECT_SOURCES_DIR ${PROJECT_DIR}/YOUR_DESIRED_DIRECTORY) +# list() = List declaration "DON'T CHANGE" +# PROJECT_SOURCES_DIR = Variable containing the listed direcotries "DON'T CHANCE +# ${PROJECT_DIR} = Direcotry of the main project this is per default the current direcotry it is defined in ked/CMakeLists.txt +list(APPEND PROJECT_SOURCES_DIR ${PROJECT_DIR}/src) +list(APPEND PROJECT_SOURCES_DIR ${PROJECT_DIR}/sensors) + +#Declaring sources to be compiled for the project. +#CMake will look in each previsouly declarec sources directory until to find this files. +set(PROJECT_SOURCES_DIR_LIST uartComm sensor) + diff --git a/libraries/examples/autoInit/sensors/sensor.c b/libraries/examples/initWithConfig/sensors/sensor.c similarity index 100% rename from libraries/examples/autoInit/sensors/sensor.c rename to libraries/examples/initWithConfig/sensors/sensor.c diff --git a/libraries/examples/autoInit/sensors/sensor.h b/libraries/examples/initWithConfig/sensors/sensor.h similarity index 100% rename from libraries/examples/autoInit/sensors/sensor.h rename to libraries/examples/initWithConfig/sensors/sensor.h diff --git a/libraries/examples/autoInit/src/uartComm.c b/libraries/examples/initWithConfig/src/uartComm.c similarity index 100% rename from libraries/examples/autoInit/src/uartComm.c rename to libraries/examples/initWithConfig/src/uartComm.c