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

master
kerem yollu 2 years ago
parent ecca9af3a3
commit 8300246f15

@ -1,20 +1,39 @@
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.18)
#################################################################################################### ####################################################################################################
# CMAKE Features # 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. 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 # Setting the used directory locations
#################################################################################################### ####################################################################################################
# Location of the project : It is defaulted to one Higher than the KED Directory :TODO: Shall we let # 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) set(PROJECT_CONFIG_FILE ${PROJECT_DIR}/projectDefinitions.cmake)
# Location of the cmkae core funtionalities / funtions / definitions # Location of the cmkae core funtionalities / funtions / definitions
set(CMAKE_CORE_DIR ${CMAKE_SOURCE_DIR}/env/cmake_core) 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 # Location of CSL, CSL_USED is passed as an argutem to CMake from run.sh
# -> "Specific to each CSL" # -> "Specific to each CSL"
@ -22,6 +41,7 @@ set(CSL_DIR ${CMAKE_SOURCE_DIR}/csl/${CSL_USED})
set(CSL_SOURCES_DIR ${CSL_DIR}/implementation) set(CSL_SOURCES_DIR ${CSL_DIR}/implementation)
set(CSL_HEADERS_DIR ${CSL_DIR}/CMSIS/Include ${CSL_DIR}/HardwareDescription) set(CSL_HEADERS_DIR ${CSL_DIR}/CMSIS/Include ${CSL_DIR}/HardwareDescription)
set(CSL_STARTUP_DIR ${CSL_DIR}/startup) 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_DIR ${CMAKE_SOURCE_DIR}/drivers)
@ -31,12 +51,10 @@ set(DRIVERS_HEADERS_DIR) #Declared empty because it will be filled automati
set(PERIPHERALS_DIR ${CMAKE_SOURCE_DIR}/peripherals) set(PERIPHERALS_DIR ${CMAKE_SOURCE_DIR}/peripherals)
set(PERIPHERALS_HEADERS_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_DIR ${CMAKE_SOURCE_DIR}/libraries)
set(LIBRARIES_HEADERS_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 # INCLUDES
@ -50,7 +68,7 @@ include(${CMAKE_CORE_DIR}/cmakeCore.cmake)
# For Detailed error messages. # For Detailed error messages.
include(${CMAKE_CORE_DIR}/errorHandler.cmake) 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}) include(${PROJECT_CONFIG_FILE})
# Here is the include fopr the awailable peripheral headers and standart libraries. # 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. # Here is the include fopr the awailable peripheral headers and standart libraries.
include(${DRIVERS_DIR}/CMakeLists.txt) include(${DRIVERS_DIR}/CMakeLists.txt)
#Include the config fiel where the compilers to use ar defined
####################################################################################################
# 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(${COMPILER_DEFS}) include(${COMPILER_DEFS})
# do this instead of declaring languages in the beginning this WILL prevent loop errors. #Confugration file of the csl, there you will wind the starup code handling, compiler/linker options, flags and definitions
project(${CSL_USED} ASM C CXX) include(${CSL_CONFIG_FILE})
#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)
#################################################################################################### ####################################################################################################
# HEADERS # HEADERS : ALL Header Definitions and calls MSUT be made here to be able to propagate them through all the modules
# ALL Header Definitions and calls MSUT be made here to be able to propagate them through all the modules
#################################################################################################### ####################################################################################################
message("${BoldBlue}") message("${BoldBlue}")
message("+-------------------------------+") message("+-------------------------------+")
message("Cheking Driver Headers") message("Cheking Driver Headers")
@ -158,14 +139,10 @@ message("Cheking User's Project")
message("+-------------------------------+") message("+-------------------------------+")
message("Included Project Headers :") message("Included Project Headers :")
checkDirectory("${PROJECT_HEADERS_DIR}") checkDirectory("${PROJECT_HEADERS_DIR}")
message("Included Project Sources :") message("Included Project Sources :")
checkDirectory("${PROJECT_SOURCES_DIR}") checkDirectory("${PROJECT_SOURCES_DIR}")
message("Declared sources :") message("Declared sources :")
foreach(X IN LISTS PROJECT_SOURCES_DIR_LIST) printList("|-->" "${PROJECT_SOURCES_DIR_LIST}")
message("|-->${X}")
endforeach()
message("Creating Libraries for declared sources :") message("Creating Libraries for declared sources :")
foreach(X IN LISTS PROJECT_SOURCES_DIR_LIST) 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. # 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}) list(APPEND GENERATED_LIBRARIES ${X})
endforeach() endforeach()
@ -194,7 +171,7 @@ message(" |--> Executable's Name\t\t\t : ${EXECUTABLE}")
message(" |--> Project's directory\t\t : ${PROJECT_DIR}") message(" |--> Project's directory\t\t : ${PROJECT_DIR}")
message(" |--> Project Configuration\t\t : ${PROJECT_DIR}/project.conf") message(" |--> Project Configuration\t\t : ${PROJECT_DIR}/project.conf")
message(" |--> Chip Support Layer Dir.\t\t : ${CSL_DIR}") 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(" |--> Compiler Definition file\t\t : ${COMPILER_DEFS}")
message(" |--> Driver Dir\t\t\t : ${DRIVERS_DIR}") message(" |--> Driver Dir\t\t\t : ${DRIVERS_DIR}")
message(" |--> Periferal Definition Dir\t\t : ${PERIPHERALS_DIR}") message(" |--> Periferal Definition Dir\t\t : ${PERIPHERALS_DIR}")
@ -204,39 +181,20 @@ message(" |--> Startup uCode Submodule:")
message(" |->${STARTUP_UCODE}") message(" |->${STARTUP_UCODE}")
message(" |--> Main Compile Definitions:") message(" |--> Main Compile Definitions:")
foreach(X IN LISTS MAIN_DEFS) printList( " | " "${MAIN_DEFS}")
message(" | ${X}")
endforeach()
message(" |--> Main Compile Flags:") message(" |--> Main Compile Flags:")
foreach(X IN LISTS MAIN_FLAGS) printList( " | " "${MAIN_FLAGS}")
message(" | ${X}")
endforeach()
message(" |--> Linker Flags:") message(" |--> Linker Flags:")
foreach(X IN LISTS LINKER_FLAGS) printList( " | " "${LINKER_FLAGS}")
message(" | ${X}")
endforeach()
message("")
message(" |--> Periferals which will be implemented:") message(" |--> Periferals which will be implemented:")
foreach(X IN LISTS PERIPHERALS_LIST) printList( " |-> " "${PERIPHERALS_LIST}")
message(" |->${X}")
endforeach()
message(" |--> Drivers which will be implemented:") message(" |--> Drivers which will be implemented:")
foreach(X IN LISTS DRIVERS_LIST) printList( " |-> " "${DRIVERS_LIST}")
message(" |->${X}")
endforeach()
message(" |--> Project sources to be implemented:") message(" |--> Project sources to be implemented:")
foreach(X IN LISTS PROJECT_SOURCES_DIR_LIST) printList( " |-> " "${PROJECT_SOURCES_DIR_LIST}")
message(" |->${X}")
endforeach()
message(" |--> Generated Library Submodules ${Red}!!!This list order also defines the compilation \ message(" |--> Generated Library Submodules ${Red}!!!This list order also defines the compilation \
order of submodules!!!${ColourReset}${BoldCyan}") order of submodules!!!${ColourReset}${BoldCyan}")
foreach(X IN LISTS GENERATED_LIBRARIES) printList( " |-> " "${GENERATED_LIBRARIES}")
message(" |->${X}")
endforeach()
message("+-------------------------------+") message("+-------------------------------+")
message("${ColourReset}") message("${ColourReset}")
@ -300,29 +258,23 @@ if(OUTPUT_DOXYGEN)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/doxyfile) set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/doxyfile)
message("${Green}") message("${Green}")
message("+-------------------------------+") message("+-------------------------------+")
message("Generation DOxygen output") message("Generating Doxygen output")
message("+-------------------------------+") message("+-------------------------------+")
message("${ColourReset}") message("${ColourReset}")
# request to configure the file # request to configure the file
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) 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 # note the option ALL which allows to build the docs together with the application
add_custom_target( doc_doxygen ALL add_custom_target( doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${DOXYGEN_WORKING_DIR} WORKING_DIRECTORY ${DOXYGEN_OUTPUT_DIR}
COMMENT "Generating API documentation with Doxygen" COMMENT "Generating API documentation with Doxygen"
VERBATIM ) VERBATIM )
message("${Green}")
message("+-------------------------------+")
message("Generating Doxygen Done")
message("+-------------------------------+")
message("${ColourReset}")
else (DOXYGEN_FOUND) else (DOXYGEN_FOUND)
message("Doxygen need to be installed to generate the doxygen documentation") message("Doxygen need to be installed to generate the doxygen documentation")
endif (DOXYGEN_FOUND) endif (DOXYGEN_FOUND)
endif(OUTPUT_DOXYGEN) endif(OUTPUT_DOXYGEN)
#################################################################################################### ####################################################################################################
#CUSTOM Comments from dev. #CUSTOM Comments from dev.
#################################################################################################### ####################################################################################################

@ -1,4 +0,0 @@
####################################################################################################
#SUBDIRECTORIES
####################################################################################################
add_subdirectory(startup)

@ -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. #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 #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) 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 # For flags please check https://manned.org/arm-none-eabi-gcc/34fd6095
set(MAIN_FLAGS set(MAIN_FLAGS
${CPU_MCU} ${CPU_MCU}
@ -28,6 +39,9 @@ set(MAIN_FLAGS
-ffunction-sections #Optimization : used with -fdata-sections -ffunction-sections #Optimization : used with -fdata-sections
$<$<CONFIG:Debug>:-O -g -gdwarf-2>) $<$<CONFIG:Debug>:-O -g -gdwarf-2>)
####################################################################################################
# DEFINITIONS
####################################################################################################
set(MAIN_DEFS set(MAIN_DEFS
-DARM_MCU #Defined by kerem to auto configure headers in main.hpp -DARM_MCU #Defined by kerem to auto configure headers in main.hpp
-DUSE_FULL_LL_DRIVER -DUSE_FULL_LL_DRIVER
@ -43,6 +57,9 @@ set(MAIN_DEFS
-DINSTRUCTION_CACHE_ENABLE=0 -DINSTRUCTION_CACHE_ENABLE=0
-DDATA_CACHE_ENABLE=0) -DDATA_CACHE_ENABLE=0)
####################################################################################################
# LINKER FLAGS
####################################################################################################
#The order is important #The order is important
set(LINKER_FLAGS set(LINKER_FLAGS
${CPU_MCU} ${CPU_MCU}
@ -55,3 +72,15 @@ set(LINKER_FLAGS
-Wl,-Map=${PROJECT_NAME}.map,--cref -Wl,-Map=${PROJECT_NAME}.map,--cref
-Wl,--gc-sections) -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)

@ -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})

@ -1,11 +1,11 @@
# Drivers # Drivers
## Description ## 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 : ## Please follow this guide to find out about the :
- [Structure](#Structure) - [Structure](#structure)
- [Usage](#Usage) - [Usage](#usage)
- [Creation](#creation) - [Creation](#creation)
- [Modification](#modification) - [Modification](#modification)
- [Credits](#credits) - [Credits](#credits)

@ -1,7 +1,16 @@
#include "lcd_oled.h" #include "lcd_oled.h"
#include "ssd1306_i2c.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 pgm_read_byte(addr) (*(const uint8_t *)(addr))
#define ssd1306_swap(a, b) { int16_t t = a; a = b; b = t; } #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) 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_off(i2c_dev);
ssd1306_i2c_set_display_clkDiv_oscFreq(i2c_dev, 0, 15); // Working but to be refined 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 ssd1306_i2c_set_multiplex_ratio(i2c_dev, LCD_OLED_SIZE_Y - 1); // Pages start at 0 and ends at 63

@ -111,3 +111,12 @@ function(addDriver alias _currentDriver)
endfunction() endfunction()
####################################################################################################
# PRINT FUNCTIONS
####################################################################################################
function(printList _txt _list)
foreach(X IN LISTS _list)
message("${_txt}${X}")
endforeach()
endfunction()

@ -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;
}

@ -1,12 +0,0 @@
#ifndef MAIN_H
#define MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* MAIN_H */

@ -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("+-------------------------------+")

@ -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()

@ -1,51 +1,25 @@
#include "i2c.h" #include "i2c.h"
#include "usart.h" #include "usart.h"
void i2c_init(i2c_t *i2c_dev)
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 */
)
{ {
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->hardwareState = i2c_hw_disabled;
i2c_dev->periferalState = i2c_perif_disabled; i2c_dev->periferalState = i2c_perif_disabled;
i2c_hardware_enable(i2c_dev); i2c_hardware_enable(i2c_dev);
i2c_periferal_disable(i2c_dev); // Just to be sure as periferal configuration can not be dont when active. 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_filter(i2c_dev,1);
i2c_set_clk_stretch(i2c_dev, stretching); i2c_set_clk_stretch(i2c_dev, i2c_dev->stretching);
i2c_set_clk_speed(i2c_dev, speed); i2c_set_clk_speed(i2c_dev, i2c_dev->speed);
i2c_set_mode(i2c_dev, mode); i2c_set_mode(i2c_dev, i2c_dev->mode);
i2c_set_address_lenght(i2c_dev, addressSize); i2c_set_address_lenght(i2c_dev, i2c_dev->addressSize);
i2c_set_address(i2c_dev, mainAddress); i2c_set_address(i2c_dev, i2c_dev->mainAddress);
i2c_set_address_second(i2c_dev, mainAddress); i2c_set_address_second(i2c_dev, i2c_dev->secondAddress);
i2c_periferal_enable(i2c_dev); 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) 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 // Arch nemesis ! We only setn the address
// but the counter allso socunt the bits that we have recieved // but the counter allso socunt the bits that we have recieved
// and we want to read one byte // and we want to read one byte
@ -107,7 +81,6 @@ uint8_t i2c_discover_devices(i2c_t *i2c_dev)
return 1; return 1;
} }
void i2c_throw_error(i2c_t *i2c_dev, uint8_t error) void i2c_throw_error(i2c_t *i2c_dev, uint8_t error)
{ {
print_Usart(usart2, "\n\r"); print_Usart(usart2, "\n\r");

@ -134,7 +134,7 @@ typedef struct i2c_t
i2c_address_count_t addressCount; /*!< Single or multiple */ i2c_address_count_t addressCount; /*!< Single or multiple */
i2c_address_size_t addressSize; /*!< 10 or 7 bit address size */ i2c_address_size_t addressSize; /*!< 10 or 7 bit address size */
i2c_clk_speed_t speed; /*!< Bus Speed */ 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 i2c_wake_types_t wakeOn; /*!< Define on which type of action the i2c channel should
wake up. Only if de prefiral goes to sleep */ wake up. Only if de prefiral goes to sleep */
i2c_hw_state_t hardwareState; /*!< The current sitate of the I2C Bus */ 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 * @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 */ 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 */
);
/** /**
* @brief De-Initilise the I2C Hardware * @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); 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 Channel is the i2c hardware channel
* @param mode The mode for i2c : Master Slave or Multymaster * @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 * @brief Set the i2c channel's address
* @param i2c_dev is the i2c hardware channel * @param i2c_dev is the i2c hardware channel
* @param address is the desired address for the device * @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); void i2c_set_address(i2c_t *i2c_dev, uint16_t address);
/** /**
* @brief Set the i2c channel's second address if the hardware allows it * @brief Set the i2c channel's second address if the hardware allows it
* @param i2c_dev is the i2c hardware channel * @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); 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 i2c_dev is the i2c hardware channel
* @param size Is the Adress isze to be used 7 Bit or 10 Bit * @param size Is the Adress isze to be used 7 Bit or 10 Bit
*/ */

@ -33,6 +33,7 @@ stmLinkInstall()
} }
build() build()
{ {
cd $SCRIPT_DIR
if [ -z "$CSL_TO_USE" ];then if [ -z "$CSL_TO_USE" ];then
echo "Please enter a CSL" echo "Please enter a CSL"
cd csl cd csl
@ -48,9 +49,9 @@ build()
cd $CMAKE_DIR cd $CMAKE_DIR
if [ -d "$BUILD_DIR" ];then if [ -d "$BUILD_DIR" ];then
rm -r $BUILD_DIR 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 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 fi
cd $BUILD_DIR cd $BUILD_DIR
@ -96,13 +97,17 @@ autoInit()
if [ "$CSL_TO_USE" == "install" ];then if [ "$CSL_TO_USE" == "install" ];then
stmLinkInstall stmLinkInstall
else else
if [[ -f "$SCRIPT_DIR/../main.c" ]];then cd $PROJECT_DIR
PROJECT_DIR=$(pwd)
if [[ -f "main.c" ]];then
build build
else else
PROJECT_DIR=$(pwd)
echo "Main.c is not fount" echo "Main.c is not fount"
echo "Creating sample project" echo "Creating sample project"
cp -r $SCRIPT_DIR/libraries/examples/autoInit/* $PROJECT_DIR/ cp -r $SCRIPT_DIR/libraries/examples/autoInit/* .
build build
echo "Main Found"
fi fi
fi fi
} }

Loading…
Cancel
Save