From 8300246f15c82ac1d5c1bced04801e2070c0aa1f Mon Sep 17 00:00:00 2001 From: kerem yollu Date: Wed, 1 Mar 2023 15:45:14 +0100 Subject: [PATCH] Cmake is taking it final shape, removed the CMakeConfig.txt from stm32f042k6t6 and also from the startup folder | i2c.c -> i2c_init Function has been canged to accep the i2cType only, this saves memory --- CMakeLists.txt | 140 ++++++------------ csl/stm32f042k6t6/CMakeLists.txt | 4 - csl/stm32f042k6t6/config.cmake | 41 ++++- csl/stm32f042k6t6/startup/CMakeLists.txt | 13 -- drivers/README.md | 6 +- drivers/lcd_oled/lcd_oled.c | 13 +- env/cmake_core/cmakeCore.cmake | 9 ++ libraries/examples/oldInit/main.c | 55 ------- libraries/examples/oldInit/main.h | 12 -- libraries/examples/oldInit/project.conf | 9 -- .../examples/oldInit/projectDefinitions.cmake | 62 -------- peripherals/i2c.c | 45 ++---- peripherals/i2c.h | 27 +--- run.sh | 13 +- 14 files changed, 130 insertions(+), 319 deletions(-) delete mode 100644 csl/stm32f042k6t6/CMakeLists.txt delete mode 100644 csl/stm32f042k6t6/startup/CMakeLists.txt delete mode 100644 libraries/examples/oldInit/main.c delete mode 100644 libraries/examples/oldInit/main.h delete mode 100644 libraries/examples/oldInit/project.conf delete mode 100644 libraries/examples/oldInit/projectDefinitions.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fd7b62..5a9dae8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,20 +1,39 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.18) #################################################################################################### # CMAKE Features #################################################################################################### -set(CMAKE_VERBOSE_MAKEFILE ON) # Should CMake print everythign ? +# do this instead of declaring languages in the beginning this WILL prevent loop errors. +project(${CSL_USED} ASM C CXX) +# Defining the executables name +set(EXECUTABLE ${PROJECT_NAME}) + +#################################################################################################### +# NON-VITAL OPTION FOR COMPILATION +#################################################################################################### + +set(CMAKE_VERBOSE_MAKEFILE OFF) # Should CMake print everythign ? + +set(OUTPUT_DOXYGEN TRUE) # Should CMake generate Doxygen output ? +set(DOXYGEN_OUTPUT_DIR ${CMAKE_SOURCE_DIR}/env/doc) + set(PL "c") # Used programming language, we could maybe do a check. +#################################################################################################### +# PASSED VARIABLE WHEN CALLING run.sh +#################################################################################################### +# CSL_USED passed by run.sh and is the quivalent of the ic name +# PROJECT_DIR Passed by run.sh and is the defined place where the project is. run.sh should be in te future capable of definin project paht. + #################################################################################################### # Setting the used directory locations #################################################################################################### # Location of the project : It is defaulted to one Higher than the KED Directory :TODO: Shall we let -set(PROJECT_DIR ${CMAKE_SOURCE_DIR}/..) set(PROJECT_CONFIG_FILE ${PROJECT_DIR}/projectDefinitions.cmake) # Location of the cmkae core funtionalities / funtions / definitions set(CMAKE_CORE_DIR ${CMAKE_SOURCE_DIR}/env/cmake_core) +set(COMPILER_DEFS ${CMAKE_CORE_DIR}/compiler.cmake) # Location of CSL, CSL_USED is passed as an argutem to CMake from run.sh # -> "Specific to each CSL" @@ -22,21 +41,20 @@ set(CSL_DIR ${CMAKE_SOURCE_DIR}/csl/${CSL_USED}) set(CSL_SOURCES_DIR ${CSL_DIR}/implementation) set(CSL_HEADERS_DIR ${CSL_DIR}/CMSIS/Include ${CSL_DIR}/HardwareDescription) set(CSL_STARTUP_DIR ${CSL_DIR}/startup) +set(CSL_CONFIG_FILE ${CSL_DIR}/config.cmake) -# Directiry fot the drivers -> "Common to all CSL" +# Directiry fot the drivers -> "Common to all CSL" set(DRIVERS_DIR ${CMAKE_SOURCE_DIR}/drivers) -set(DRIVERS_HEADERS_DIR) #Declared empty because it will be filled automaticaly afterwards +set(DRIVERS_HEADERS_DIR) #Declared empty because it will be filled automaticaly afterwards # Directory fot the peripherals -> "Common to all CSL" set(PERIPHERALS_DIR ${CMAKE_SOURCE_DIR}/peripherals) set(PERIPHERALS_HEADERS_DIR ${CMAKE_SOURCE_DIR}/peripherals) +# Directory for the libraries -> "Common to all CSL" set(LIBRARIES_DIR ${CMAKE_SOURCE_DIR}/libraries) set(LIBRARIES_HEADERS_DIR ${CMAKE_SOURCE_DIR}/libraries) -# Variable for Doxygen generation -set(OUTPUT_DOXYGEN TRUE) # Should CMake generate Doxygen output ? -set(DOXYGEN_WORKING_DIR ${CMAKE_SOURCE_DIR}/env/doc) #################################################################################################### # INCLUDES @@ -50,7 +68,7 @@ include(${CMAKE_CORE_DIR}/cmakeCore.cmake) # For Detailed error messages. include(${CMAKE_CORE_DIR}/errorHandler.cmake) -# Here is the include Where the user sould define his project sources and headers +# Include the project definition defined by the end user implementiogn KED as a submodule include(${PROJECT_CONFIG_FILE}) # Here is the include fopr the awailable peripheral headers and standart libraries. @@ -59,52 +77,15 @@ include(${PERIPHERALS_DIR}/CMakeLists.txt) # Here is the include fopr the awailable peripheral headers and standart libraries. include(${DRIVERS_DIR}/CMakeLists.txt) - -#################################################################################################### -# Cheking if the choosen CSL exists, this i redundant because run.sh makes that alredy but makes the -# code future proof. Goal would be to not use a run.sh if the user doesn't need help -#################################################################################################### -if(EXISTS ${CSL_DIR}) # Cheking if the directory exists - message("${Green}") - message("+-------------------------------+") - message("Compiling for ${CSL_USED}") - message("+-------------------------------+") - message("Project dir : ${PROJECT_DIR}") - message("+-------------------------------+") - message("${ColourReset}") - set(COMPILER_DEFS ${CMAKE_CORE_DIR}/compiler.cmake) # TODO : Change location - set(CSL_DEFS ${CSL_DIR}/config.cmake) - -else() - message("${Red}") - message( FATAL_ERROR "\nPlease Select a valid CSL, CMake will exit\n") - message("${ColourReset}") -endif() - +#Include the config fiel where the compilers to use ar defined include(${COMPILER_DEFS}) -# do this instead of declaring languages in the beginning this WILL prevent loop errors. -project(${CSL_USED} ASM C CXX) - -#Create the executable -set(EXECUTABLE ${PROJECT_NAME}) - -#################################################################################################### -# SUBDIRECTORIES Will add the given folders to the porject an check for CmakeLists.txt -#################################################################################################### -include(${CSL_DEFS}) -add_subdirectory(${CSL_DIR}) - -#################################################################################################### -# Sartupt uCode Definition this part Is left alone on purpose ! -#################################################################################################### -set(STARTUP_UCODE sub::startup) +#Confugration file of the csl, there you will wind the starup code handling, compiler/linker options, flags and definitions +include(${CSL_CONFIG_FILE}) #################################################################################################### -# HEADERS -# ALL Header Definitions and calls MSUT be made here to be able to propagate them through all the modules +# HEADERS : ALL Header Definitions and calls MSUT be made here to be able to propagate them through all the modules #################################################################################################### - message("${BoldBlue}") message("+-------------------------------+") message("Cheking Driver Headers") @@ -158,14 +139,10 @@ message("Cheking User's Project") message("+-------------------------------+") message("Included Project Headers :") checkDirectory("${PROJECT_HEADERS_DIR}") - message("Included Project Sources :") checkDirectory("${PROJECT_SOURCES_DIR}") - message("Declared sources :") -foreach(X IN LISTS PROJECT_SOURCES_DIR_LIST) - message("|-->${X}") -endforeach() +printList("|-->" "${PROJECT_SOURCES_DIR_LIST}") message("Creating Libraries for declared sources :") foreach(X IN LISTS PROJECT_SOURCES_DIR_LIST) @@ -179,7 +156,7 @@ message("${ColourReset}") #################################################################################################### # Stick All the libraries together, only for code redability futher down. #################################################################################################### -foreach(X IN LISTS STARTUP_UCODE PROJECT_LIBS PERIPHERAL_LIBS DRIVER_LIBS ) +foreach(X IN LISTS STARTUP_UCODE PROJECT_LIBS PERIPHERAL_LIBS DRIVER_LIBS) list(APPEND GENERATED_LIBRARIES ${X}) endforeach() @@ -194,7 +171,7 @@ message(" |--> Executable's Name\t\t\t : ${EXECUTABLE}") message(" |--> Project's directory\t\t : ${PROJECT_DIR}") message(" |--> Project Configuration\t\t : ${PROJECT_DIR}/project.conf") message(" |--> Chip Support Layer Dir.\t\t : ${CSL_DIR}") -message(" |--> CLS's cmake configuration\t\t : ${CSL_DEFS}") +message(" |--> CLS's cmake configuration\t\t : ${CSL_CONFIG_FILE}") message(" |--> Compiler Definition file\t\t : ${COMPILER_DEFS}") message(" |--> Driver Dir\t\t\t : ${DRIVERS_DIR}") message(" |--> Periferal Definition Dir\t\t : ${PERIPHERALS_DIR}") @@ -204,39 +181,20 @@ message(" |--> Startup uCode Submodule:") message(" |->${STARTUP_UCODE}") message(" |--> Main Compile Definitions:") -foreach(X IN LISTS MAIN_DEFS) - message(" | ${X}") -endforeach() +printList( " | " "${MAIN_DEFS}") message(" |--> Main Compile Flags:") -foreach(X IN LISTS MAIN_FLAGS) - message(" | ${X}") -endforeach() +printList( " | " "${MAIN_FLAGS}") message(" |--> Linker Flags:") -foreach(X IN LISTS LINKER_FLAGS) - message(" | ${X}") -endforeach() - -message("") +printList( " | " "${LINKER_FLAGS}") message(" |--> Periferals which will be implemented:") -foreach(X IN LISTS PERIPHERALS_LIST) - message(" |->${X}") -endforeach() - -message(" |--> Drivers which will be implemented:") -foreach(X IN LISTS DRIVERS_LIST) - message(" |->${X}") -endforeach() - -message(" |--> Project sources to be implemented:") -foreach(X IN LISTS PROJECT_SOURCES_DIR_LIST) - message(" |->${X}") -endforeach() - +printList( " |-> " "${PERIPHERALS_LIST}") +message(" |--> Drivers which will be implemented:") +printList( " |-> " "${DRIVERS_LIST}") +message(" |--> Project sources to be implemented:") +printList( " |-> " "${PROJECT_SOURCES_DIR_LIST}") message(" |--> Generated Library Submodules ${Red}!!!This list order also defines the compilation \ order of submodules!!!${ColourReset}${BoldCyan}") -foreach(X IN LISTS GENERATED_LIBRARIES) - message(" |->${X}") -endforeach() +printList( " |-> " "${GENERATED_LIBRARIES}") message("+-------------------------------+") message("${ColourReset}") @@ -300,29 +258,23 @@ if(OUTPUT_DOXYGEN) set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/doxyfile) message("${Green}") message("+-------------------------------+") - message("Generation DOxygen output") + message("Generating Doxygen output") message("+-------------------------------+") message("${ColourReset}") # request to configure the file configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) - message("Doxygen build started") - # note the option ALL which allows to build the docs together with the application add_custom_target( doc_doxygen ALL COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} - WORKING_DIRECTORY ${DOXYGEN_WORKING_DIR} + WORKING_DIRECTORY ${DOXYGEN_OUTPUT_DIR} COMMENT "Generating API documentation with Doxygen" VERBATIM ) - message("${Green}") - message("+-------------------------------+") - message("Generating Doxygen Done") - message("+-------------------------------+") - message("${ColourReset}") else (DOXYGEN_FOUND) message("Doxygen need to be installed to generate the doxygen documentation") endif (DOXYGEN_FOUND) endif(OUTPUT_DOXYGEN) + #################################################################################################### #CUSTOM Comments from dev. #################################################################################################### diff --git a/csl/stm32f042k6t6/CMakeLists.txt b/csl/stm32f042k6t6/CMakeLists.txt deleted file mode 100644 index 67bad89..0000000 --- a/csl/stm32f042k6t6/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -#################################################################################################### -#SUBDIRECTORIES -#################################################################################################### -add_subdirectory(startup) diff --git a/csl/stm32f042k6t6/config.cmake b/csl/stm32f042k6t6/config.cmake index a87af5c..4629a34 100644 --- a/csl/stm32f042k6t6/config.cmake +++ b/csl/stm32f042k6t6/config.cmake @@ -1,9 +1,3 @@ -#################################################################################################### -# bsl_nucleo_f042k6.cmake -#################################################################################################### - -set(CPU_MCU "-mcpu=cortex-m0") - #################################################################################################### #PROJECT & LIBRARIES : defined by user and important that it comes after the VARIABLES otherwise the Set varibale will not be used. #################################################################################################### @@ -15,8 +9,25 @@ set(CMAKE_CROSSCOMPILING TRUE) #################################################################################################### #VARIABLES : defined by user #################################################################################################### +# Set the required Startup Code +set(STARTUP_CODE ${CSL_STARTUP_DIR}/startup_stm32f042x6.s) + +# Sartup can and will most propably require some extra flags +set(STARTUP_FLAGS -x assembler-with-cpp ${MAIN_FLAGS}) + +# Defines should be the same as the other sources but somes extras could be added if needed +set(STARTUP_DEFS ${MAIN_DEFS}) + +# Defines the linker to be used set(LINKER ${CSL_STARTUP_DIR}/STM32F042K6Tx_FLASH.ld) +# Defines The MCU CORE +set(CPU_MCU "-mcpu=cortex-m0") + + +#################################################################################################### +# MAIN COMPILING FLAGS +#################################################################################################### # For flags please check https://manned.org/arm-none-eabi-gcc/34fd6095 set(MAIN_FLAGS ${CPU_MCU} @@ -28,6 +39,9 @@ set(MAIN_FLAGS -ffunction-sections #Optimization : used with -fdata-sections $<$:-O -g -gdwarf-2>) +#################################################################################################### +# DEFINITIONS +#################################################################################################### set(MAIN_DEFS -DARM_MCU #Defined by kerem to auto configure headers in main.hpp -DUSE_FULL_LL_DRIVER @@ -43,6 +57,9 @@ set(MAIN_DEFS -DINSTRUCTION_CACHE_ENABLE=0 -DDATA_CACHE_ENABLE=0) +#################################################################################################### +# LINKER FLAGS +#################################################################################################### #The order is important set(LINKER_FLAGS ${CPU_MCU} @@ -55,3 +72,15 @@ set(LINKER_FLAGS -Wl,-Map=${PROJECT_NAME}.map,--cref -Wl,--gc-sections) +#################################################################################################### +# Creation of the startup library : Use only needs to chnage the definitions made at the beginning +#################################################################################################### +add_library(startup ${STARTUP_CODE}) +target_compile_options(startup PRIVATE ${STARTUP_FLAGS}) +target_compile_definitions(startup PRIVATE ${STARTUP_DEFS}) +add_library(sub::startup ALIAS startup) + +#################################################################################################### +# Sartupt uCode Definition this part Is left alone on purpose ! +#################################################################################################### +set(STARTUP_UCODE sub::startup) diff --git a/csl/stm32f042k6t6/startup/CMakeLists.txt b/csl/stm32f042k6t6/startup/CMakeLists.txt deleted file mode 100644 index 5e57df4..0000000 --- a/csl/stm32f042k6t6/startup/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -project(Startup) - -set (AS_SOURCES startup_stm32f042x6.s) -set (AS_INCLUDES ${C_INCLUDES}) -set (AS_FLAGS -x assembler-with-cpp ${C_FLAGS}) -set (AS_DEFS ${C_DEFS}) - -add_library(${PROJECT_NAME} ${AS_SOURCES}) -target_compile_options(${PROJECT_NAME} PRIVATE ${AS_FLAGS}) -target_compile_definitions(${PROJECT_NAME} PRIVATE ${AS_DEFS}) - -#To create an alias to be used on the main CMAKE. -add_library(sub::startup ALIAS ${PROJECT_NAME}) diff --git a/drivers/README.md b/drivers/README.md index b44e270..e9dd77a 100644 --- a/drivers/README.md +++ b/drivers/README.md @@ -1,11 +1,11 @@ # Drivers ## Description -Drivers are the higher level of code prowided by *KED*. It come on top of the [Peripheras](https://git.keydev.me/kerem/KED/src/branch/master/peripherals) and alows the usage of comercially awailable IC's or moludes. +Drivers are the higher level of code provided by *KED*. It comes on top of the [Peripherals](https://git.keydev.me/kerem/KED/src/branch/master/peripherals) and alows the usage of comercially awailable IC's or moludes. --- ## Please follow this guide to find out about the : -- [Structure](#Structure) -- [Usage](#Usage) +- [Structure](#structure) +- [Usage](#usage) - [Creation](#creation) - [Modification](#modification) - [Credits](#credits) diff --git a/drivers/lcd_oled/lcd_oled.c b/drivers/lcd_oled/lcd_oled.c index 22b6706..02f1dc4 100644 --- a/drivers/lcd_oled/lcd_oled.c +++ b/drivers/lcd_oled/lcd_oled.c @@ -1,7 +1,16 @@ #include "lcd_oled.h" #include "ssd1306_i2c.h" -i2c_t i2c_device; +i2c_t i2c_device = { 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 */ + #define pgm_read_byte(addr) (*(const uint8_t *)(addr)) #define ssd1306_swap(a, b) { int16_t t = a; a = b; b = t; } @@ -77,7 +86,7 @@ uint8_t display_buffer[LCD_OLED_SIZE_X * LCD_OLED_SIZE_Y / 8] = { void lcd_oled_init(i2c_t *i2c_dev, uint8_t address) { - i2c_init(&i2c_device, 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_device); ssd1306_i2c_set_display_off(i2c_dev); ssd1306_i2c_set_display_clkDiv_oscFreq(i2c_dev, 0, 15); // Working but to be refined ssd1306_i2c_set_multiplex_ratio(i2c_dev, LCD_OLED_SIZE_Y - 1); // Pages start at 0 and ends at 63 diff --git a/env/cmake_core/cmakeCore.cmake b/env/cmake_core/cmakeCore.cmake index f680b49..e878634 100755 --- a/env/cmake_core/cmakeCore.cmake +++ b/env/cmake_core/cmakeCore.cmake @@ -111,3 +111,12 @@ function(addDriver alias _currentDriver) endfunction() +#################################################################################################### +# PRINT FUNCTIONS +#################################################################################################### +function(printList _txt _list) + foreach(X IN LISTS _list) + message("${_txt}${X}") + endforeach() +endfunction() + diff --git a/libraries/examples/oldInit/main.c b/libraries/examples/oldInit/main.c deleted file mode 100644 index 2e0003e..0000000 --- a/libraries/examples/oldInit/main.c +++ /dev/null @@ -1,55 +0,0 @@ -#include "main.h" -#include "delay.h" -#include "deviceSetup.h" -#include "usart.h" -#include "ascii.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. - - usartInit( usart2, - pinA2, - pinA15, - 115200, - eight, - NO_PARITY_CTRL, - noFlowControl); - - //clears screen and send the wellcome messgae - print_Usart(usart2, ASCII_clear); - print_Usart(usart2, "Hello to our KED project\n\r"); - - - //blinks 10 times to indicate the sicsessfull init if the device - for(i = 0 ; i < 2 ; i++) { - delayMs(100); - pinToggle(pinB3); - delayMs(100); - } - - pinWrite(pinB3,0); - - print_Usart(usart2, "\n\r"); - - print_Usart(usart2, "\n\r"); - print_Usart(usart2, "\n\r"); - print_Usart(usart2, "All is working fine\n\r"); - - while(1) - { - delayMs(100); - pinToggle(pinB3); - delayMs(100); - } - - return 1; -} - diff --git a/libraries/examples/oldInit/main.h b/libraries/examples/oldInit/main.h deleted file mode 100644 index 4c01ad6..0000000 --- a/libraries/examples/oldInit/main.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef MAIN_H -#define MAIN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* MAIN_H */ diff --git a/libraries/examples/oldInit/project.conf b/libraries/examples/oldInit/project.conf deleted file mode 100644 index 9f9e997..0000000 --- a/libraries/examples/oldInit/project.conf +++ /dev/null @@ -1,9 +0,0 @@ -set(PROJEC_HEADERS ${CMAKE_SOURCE_DIR}/../headers) -set(PROJEC_SOURCES ${CMAKE_SOURCE_DIR}/../sr) - -message("+-------------------------------+") -message("Project Includes") -message("+-------------------------------+") -message("Project Headers : ${PROJEC_HEADERS}") -message("Project Sources : ${PROJEC_SOURCES}") -message("+-------------------------------+") diff --git a/libraries/examples/oldInit/projectDefinitions.cmake b/libraries/examples/oldInit/projectDefinitions.cmake deleted file mode 100644 index e28c559..0000000 --- a/libraries/examples/oldInit/projectDefinitions.cmake +++ /dev/null @@ -1,62 +0,0 @@ -#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.c sensor.c) - -#Searching if the given header directory exists if not we brake the compilation -function(projectHeadersCheck) - foreach(X IN LISTS PROJECT_HEADERS_DIR) - if(EXISTS ${X}) - message("|--> ${X} : INCLUDED") - else() - message(FATAL_ERROR "Header directory ${X} : NOT FOUND") - endif() - endforeach() -endfunction() - -#Searching if the given Source exists if not we brake the compilation -function(projectCheckSourcesCheck) - foreach(X IN LISTS PROJECT_SOURCES_DIR) - if(EXISTS ${X}) - message("|--> ${X} : INCLUDED") - else() - message(FATAL_ERROR "Source directory ${X} : NOT FOUND") - endif() - endforeach() -endfunction() - -#Searching each sources directory to find the desired source file and generate a libaray submodule for the linker -function(projectAddItem alias _currentItem) - foreach(X IN LISTS PROJECT_SOURCES_DIR) - if(EXISTS ${X}) - if(EXISTS ${X}/${alias}) #For each directory we chanek if the given source file exitst - message("|-->${alias} FOUND in : ${X}") - message(" |-> Creating sub::${alias} library submodule") - add_library(${alias}_submodule ${X}/${alias}) - target_compile_options(${alias}_submodule PRIVATE ${C_FLAGS}) - target_compile_definitions(${alias}_submodule PRIVATE ${C_DEFS}) - target_include_directories(${alias}_submodule PUBLIC ${PROJECT_HEADERS_DIR} ${PERIFERALS_DIR} ${CSL_INCLUDES}) - add_library(sub::${alias} ALIAS ${alias}_submodule) - set(${_currentItem} sub::${alias} PARENT_SCOPE) - endif() - else() - message(FATAL_ERROR "Source directory ${X} : NOT FOUND") - endif() - endforeach() -endfunction() diff --git a/peripherals/i2c.c b/peripherals/i2c.c index 18b9ecd..b86d794 100644 --- a/peripherals/i2c.c +++ b/peripherals/i2c.c @@ -1,51 +1,25 @@ #include "i2c.h" #include "usart.h" - -void i2c_init( i2c_t *i2c_dev, /*!< Pointer to I2C hardware Object */ - i2cCh_t channelNo, /*!< The harware channel to be used */ - i2c_mode_t mode, /*!< Master, Slave or Multymaster Modes */ - uint16_t mainAddress, /*!< First and Main address of the device */ - uint16_t secondAddress, /*!< Second address if dual addresse mode is configured */ - i2c_address_count_t addressCount, /*!< Single or multiple */ - i2c_address_size_t addressSize, /*!< 10 or 7 bit address size */ - i2c_clk_speed_t speed, /*!< Bus Speed */ - i2c_clk_stretching_t stretching, /*!< Clock Stretching enable onyl in slave mode */ - i2c_wake_types_t wakeOn /*!< Wake up condition */ - ) +void i2c_init(i2c_t *i2c_dev) { - i2c_dev->channelNo = channelNo; - i2c_dev->mode = mode; - i2c_dev->mainAddress = mainAddress; - i2c_dev->secondAddress = secondAddress; - i2c_dev->addressCount = addressCount; - i2c_dev->addressSize = addressSize; - i2c_dev->speed = speed; - i2c_dev->stretching = stretching; - i2c_dev->wakeOn = wakeOn; - - //Initial state States i2c_dev->hardwareState = i2c_hw_disabled; - i2c_dev->periferalState = i2c_perif_disabled; - + i2c_dev->periferalState = i2c_perif_disabled; i2c_hardware_enable(i2c_dev); i2c_periferal_disable(i2c_dev); // Just to be sure as periferal configuration can not be dont when active. i2c_set_filter(i2c_dev,1); - i2c_set_clk_stretch(i2c_dev, stretching); - i2c_set_clk_speed(i2c_dev, speed); - i2c_set_mode(i2c_dev, mode); - i2c_set_address_lenght(i2c_dev, addressSize); - i2c_set_address(i2c_dev, mainAddress); - i2c_set_address_second(i2c_dev, mainAddress); + i2c_set_clk_stretch(i2c_dev, i2c_dev->stretching); + i2c_set_clk_speed(i2c_dev, i2c_dev->speed); + i2c_set_mode(i2c_dev, i2c_dev->mode); + i2c_set_address_lenght(i2c_dev, i2c_dev->addressSize); + i2c_set_address(i2c_dev, i2c_dev->mainAddress); + i2c_set_address_second(i2c_dev, i2c_dev->secondAddress); i2c_periferal_enable(i2c_dev); - print_Usart(usart2, "\n\rI2C -> periferal enabled\n\r"); } void i2c_read(i2c_t *i2c_dev, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data, uint8_t *dataLenght) { - - i2c_dev->periferalState = i2c_perif_read; - + i2c_dev->periferalState = i2c_perif_read; // Arch nemesis ! We only setn the address // but the counter allso socunt the bits that we have recieved // and we want to read one byte @@ -107,7 +81,6 @@ uint8_t i2c_discover_devices(i2c_t *i2c_dev) return 1; } - void i2c_throw_error(i2c_t *i2c_dev, uint8_t error) { print_Usart(usart2, "\n\r"); diff --git a/peripherals/i2c.h b/peripherals/i2c.h index c8423e6..1bc3023 100644 --- a/peripherals/i2c.h +++ b/peripherals/i2c.h @@ -134,7 +134,7 @@ typedef struct i2c_t i2c_address_count_t addressCount; /*!< Single or multiple */ i2c_address_size_t addressSize; /*!< 10 or 7 bit address size */ i2c_clk_speed_t speed; /*!< Bus Speed */ - i2c_clk_stretching_t stretching; /*!< Clock Stretching enable onyl in slave mode */ + i2c_clk_stretching_t stretching; /*!< Clock Stretching enable only in slave mode */ i2c_wake_types_t wakeOn; /*!< Define on which type of action the i2c channel should wake up. Only if de prefiral goes to sleep */ i2c_hw_state_t hardwareState; /*!< The current sitate of the I2C Bus */ @@ -147,28 +147,18 @@ typedef struct i2c_t /** * @brief Initilize the I2C Hardware - * @param i2c_dev is the beforehand declared i2c channel with his opperation modes + * @param i2c_dev is the beforehand declared i2c channel. */ -void i2c_init( i2c_t *i2c_dev, /*!< Pointer to I2C hardware Object */ - i2cCh_t channelNo, /*!< The harware channel to be used */ - i2c_mode_t mode, /*!< Master, Slave or Multymaster Modes */ - uint16_t mainAddress, /*!< First and Main address of the device */ - uint16_t secondAddress, /*!< Second address if dual addresse mode is configured */ - i2c_address_count_t addressCount, /*!< Single or multiple */ - i2c_address_size_t addressSize, /*!< 10 or 7 bit address size */ - i2c_clk_speed_t speed, /*!< Bus Speed */ - i2c_clk_stretching_t stretching, /*!< Clock Stretching enable onyl in slave mode */ - i2c_wake_types_t wakeOn /*!< Wake up condition */ - ); - +void i2c_init(i2c_t *i2c_dev); /*!< Pointer to I2C hardware Object */ + /** * @brief De-Initilise the I2C Hardware - * @param i2c_dev is the beforehand declared i2c channel with his opperation modes + * @param i2c_dev is the beforehand declared i2c channel. */ void i2c_deinitialise(i2c_t *i2c_dev); /** - * @brief Set the i2c channle to the gievn mode + * @brief Set the i2c channel to master, slave or mutymaster modes * @param Channel is the i2c hardware channel * @param mode The mode for i2c : Master Slave or Multymaster */ @@ -178,19 +168,18 @@ void i2c_set_mode(i2c_t *i2c_dev, i2c_mode_t mode); * @brief Set the i2c channel's address * @param i2c_dev is the i2c hardware channel * @param address is the desired address for the device - * @param addressTwo The second address for the device only if dual address mode is not defined */ void i2c_set_address(i2c_t *i2c_dev, uint16_t address); /** * @brief Set the i2c channel's second address if the hardware allows it * @param i2c_dev is the i2c hardware channel - * @param address is the desired address for the device + * @param address The second address */ void i2c_set_address_second(i2c_t *i2c_dev, uint16_t address); /** - * @brief Set the i2c Address Lenght, 7 bit or 8 bit, Master or slave doesn't make any difference + * @brief Set the i2c Address Lenght to 7 or 10 bits, Master or Slave doesn't make any difference * @param i2c_dev is the i2c hardware channel * @param size Is the Adress isze to be used 7 Bit or 10 Bit */ diff --git a/run.sh b/run.sh index fe48cea..3cd61d8 100755 --- a/run.sh +++ b/run.sh @@ -33,6 +33,7 @@ stmLinkInstall() } build() { + cd $SCRIPT_DIR if [ -z "$CSL_TO_USE" ];then echo "Please enter a CSL" cd csl @@ -48,9 +49,9 @@ build() cd $CMAKE_DIR if [ -d "$BUILD_DIR" ];then rm -r $BUILD_DIR - cmake -S . -B $BUILD_DIR -DCSL_USED=$CSL_TO_USE + cmake -S . -B $BUILD_DIR -DCSL_USED=$CSL_TO_USE -DPROJECT_DIR=$PROJECT_DIR else - cmake -S . -B $BUILD_DIR -DCSL_USED=$CSL_TO_USE + cmake -S . -B $BUILD_DIR -DCSL_USED=$CSL_TO_USE -DPROJECT_DIR=$PROJECT_DIR fi cd $BUILD_DIR @@ -96,13 +97,17 @@ autoInit() if [ "$CSL_TO_USE" == "install" ];then stmLinkInstall else - if [[ -f "$SCRIPT_DIR/../main.c" ]];then + cd $PROJECT_DIR + PROJECT_DIR=$(pwd) + if [[ -f "main.c" ]];then build else + PROJECT_DIR=$(pwd) echo "Main.c is not fount" echo "Creating sample project" - cp -r $SCRIPT_DIR/libraries/examples/autoInit/* $PROJECT_DIR/ + cp -r $SCRIPT_DIR/libraries/examples/autoInit/* . build + echo "Main Found" fi fi }