-
Notifications
You must be signed in to change notification settings - Fork 0
EHL-2 i2c library #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sajidanower23
wants to merge
29
commits into
master
Choose a base branch
from
EHL-2-I2C-Library
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b3eaa57
EHL-1 #time 4h Messed with the build system until test file built
wmpmiles a4feec8
EHL-2 Initial commit #time 3hr finished common i2c interface and si7021
burrrrrr 807c13d
EHL-2 Added libraries #time 2hr ported arduino libraries for lis3mdl …
burrrrrr 7be4c78
EHL-2 #time 30min hx711 library and cleaned up bugs
burrrrrr ea32507
EHL-2 #time 10min Added makefile
burrrrrr 22205f3
EHL-2 #time 2hr Added science module
burrrrrr 020ea31
Merge branch 'master' into EHL-2-I2C-Library
burrrrrr a885a54
EHL-2 #time 20m Fixed compile errors
burrrrrr 75ac603
EHL-2 #time 1m Re-added some headers as uppercase
burrrrrr 728f557
EHL-2 #time 5m Modified CMakeLists
00bc5bf
EHL-2 #time 2h Science library now working
burrrrrr 74175a7
EHL-1 #time 3h debugging, adc working in polling and interrupt mode
burrrrrr 049457d
Merge branch 'EHL-1-adc' into EHL-2-I2C-Library
burrrrrr cc4c7c4
EHL-2 #time 30m added moisture, weight, multiplexer to test file
burrrrrr 34ac382
EHL-2 #time 5m modified weight sensor sample average
burrrrrr 2953c22
EHL-2 #time 3h Science servo calibrated, added everything to science …
burrrrrr ab221d8
Increase stack size for good measure
sajidanower23 3416e3c
Whitespace cleanup
sajidanower23 2d1ee93
Initialise all sensors on all boards
sajidanower23 e141f78
Comment in code for testing
sajidanower23 2fd108d
Ignore editor settings
sajidanower23 8d581e1
Add in adc sensors
sajidanower23 f0ee6e6
Fix license header
sajidanower23 7db9c1b
Change from 4 to 3 modules
sajidanower23 fd7c697
Style tweaks
sajidanower23 2b0f083
Use 3 boards instead of 4
sajidanower23 3a7133f
Add adc_capure_polling back in
sajidanower23 ebe74ee
Make topic use float64
sajidanower23 8fa976b
Add dummy data
sajidanower23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,3 +189,4 @@ venv.bak/ | |
|
|
||
| # mypy | ||
| .mypy_cache/ | ||
| .vscode/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/bin/sh | ||
|
|
||
| if [ $# -eq 0 ] | ||
| then | ||
| echo "Usage: sudo $0 <module>" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ ! `ls elfs | grep "^$1\.elf$"` ] | ||
| then | ||
| echo "No module called \"$1\"" | ||
| exit 1 | ||
| fi | ||
|
|
||
| openocd="sudo openocd -f board/ek-tm4c123gxl.cfg" | ||
| serial="sleep 1; picocom -b 115200 /dev/ttyACM0" | ||
| debug="sleep 2; ./flash.sh elfs/$1.elf" | ||
|
|
||
| gnome-terminal --tab --command="bash -c '$openocd; $SHELL'" \ | ||
| --tab --command="bash -c '$serial; $SHELL'" \ | ||
| --tab --command="bash -c '$debug; $SHELL'" \ | ||
| --disable-factory | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| project(adc) | ||
| cmake_minimum_required(VERSION 3.5) | ||
|
|
||
| find_package(catkin REQUIRED | ||
| COMPONENTS ti) | ||
|
|
||
| catkin_package( | ||
| INCLUDE_DIRS ./ | ||
| LIBRARIES adc | ||
| CATKIN_DEPENDS ti | ||
| ) | ||
|
|
||
| set(BUILD_TOOLS_DIR ../../../build-tools) | ||
| include(../../../build-tools/build_env.cmake) | ||
|
|
||
| add_library(adc STATIC adc.c) | ||
| target_include_directories(adc PUBLIC | ||
| ${CMAKE_INCLUDE_PATH} | ||
| ./ | ||
| ${catkin_INCLUDE_DIRS} | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| Initialisation: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for all files that are in common please address comments on #12 before merging this (all the adc stuff) |
||
| 1. Enable ADC clock if not enabled | ||
| 2. Enable GPIO clock if not enabled | ||
| 3. Set GPIO AFSEL bit ? | ||
| 4. Clear GPIO DEN bit in GPIODEN | ||
| 5. Disable analogue isolation via GPIOAMSEL | ||
| 6. Disable sample sequencer via ASENn in ADCACTSS | ||
| 7. Append new source to sequencer via ADCSSCTLn | ||
| 8. Enable sample sequencer via ASENn in ADCACTSS | ||
|
|
||
| Notes | ||
| - ADC should use PIOSC for clock at 1 divider for clock | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| Differential pair count = 4 | ||
|
|
||
| When VIN+ == VIN- the output will be 0x800 | ||
|
|
||
| Pair map | ||
| VIND0 <= AIN0 - AIN1 | ||
| VIND1 <= AIN2 - AIN3 | ||
| VIND2 <= AIN4 - AIN5 | ||
| VIND3 <= AIN6 - AIN7 | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| The internal temperature sensor can be accessed as part of a sample | ||
| sequence by setting the relevant TSn bit in ADCSSCTLn register. | ||
|
|
||
| The sample can be converted into a temperature with: | ||
| TEMP = 147.5 - ((75 * (VREFP - VREFN) × ADC CODE ) / 4096) | ||
| Accuracy is +- 5 degrees celsius. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| Pin count = 9 | ||
|
|
||
| Pin map: | ||
| AIN0 => PE3 | ||
| AIN1 => PE2 | ||
| AIN2 => PE1 | ||
| AIN3 => PE0 | ||
| AIN4 => PD7 | ||
| AIN5 => PD6 | ||
| AIN6 => PD5 | ||
| AIN7 => PD4 | ||
| AIN20 => PE7 | ||
|
|
||
| Pin inputs: | ||
| GPIO | ||
| AIN0 | ||
| AIN1 | ||
| AIN2 | ||
| AIN3 | ||
| AIN4 | ||
| AIN5 | ||
| AIN6 | ||
| AIN7 | ||
| AIN20 | ||
| Filtered input? | ||
| AIN0 | ||
| AIN1 | ||
| AIN2 | ||
| AIN3 | ||
| Current sensor | ||
| AIN7 | ||
| Temperature sensor | ||
| AIN20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| VREFA+ => 3V from a precision voltage reference IC | ||
| VREFA- => 0V from ground |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| //------------------------------INCLUDES------------------------------// | ||
| #include "adc.h" | ||
|
|
||
| //---------------------------ERROR_HANDLING---------------------------// | ||
|
|
||
| //---------------------------SIZE_CONSTANTS---------------------------// | ||
| #define PC 8 /* ADC pin count */ | ||
| #define GPIO_PORT_COUNT 2 /* number of GPIO ports used by ADC */ | ||
|
|
||
|
|
||
| //-------------------------------ENUMS--------------------------------// | ||
| enum { | ||
| PRE_INIT, | ||
| POST_INIT | ||
| }; | ||
|
|
||
| //------------------------------STRUCTS-------------------------------// | ||
| struct gpio_port { | ||
| const uint32_t sysctl; | ||
| const uint32_t base; | ||
| }; /* struct for data required for manipulating GPIO ports */ | ||
|
|
||
| struct gpio_pin { | ||
| const struct gpio_port port; | ||
| const uint8_t pin; | ||
| }; | ||
|
|
||
|
|
||
| //---------------------SHARED_HARDWARE_CONSTANTS----------------------// | ||
| /* ADC configuration arguments */ | ||
| const uint32_t adc_clock_div = 1; | ||
| const uint32_t adc_clock_config = | ||
| ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_FULL; | ||
| const uint32_t sequence_num = 0; | ||
| const uint32_t adc_sc_module = SYSCTL_PERIPH_ADC0; | ||
|
|
||
|
|
||
| //----------------------BOARD_SPECIFIC_CONSTANTS----------------------// | ||
| #ifdef PART_TM4C123GH6PM | ||
| const uint32_t adc_reference = ADC_REF_INT; | ||
|
|
||
| const struct gpio_pin gpio_lut[PC] = { | ||
| {{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_3}, | ||
| {{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_2}, | ||
| {{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_1}, | ||
| {{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_0}, | ||
| {{SYSCTL_PERIPH_GPIOB, GPIO_PORTB_BASE}, GPIO_PIN_7}, | ||
| {{SYSCTL_PERIPH_GPIOB, GPIO_PORTB_BASE}, GPIO_PIN_6}, | ||
| {{SYSCTL_PERIPH_GPIOB, GPIO_PORTB_BASE}, GPIO_PIN_5}, | ||
| {{SYSCTL_PERIPH_GPIOB, GPIO_PORTB_BASE}, GPIO_PIN_4}}; | ||
| #endif | ||
| #ifdef PART_TM4C123GH6PGE | ||
| const uint32_t adc_reference = ADC_REF_EXT_3V; | ||
|
|
||
| const struct gpio_pin gpio_lut[PC] = { | ||
| {{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_3}, | ||
| {{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_2}, | ||
| {{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_1}, | ||
| {{SYSCTL_PERIPH_GPIOE, GPIO_PORTE_BASE}, GPIO_PIN_0}, | ||
| {{SYSCTL_PERIPH_GPIOD, GPIO_PORTD_BASE}, GPIO_PIN_7}, | ||
| {{SYSCTL_PERIPH_GPIOD, GPIO_PORTD_BASE}, GPIO_PIN_6}, | ||
| {{SYSCTL_PERIPH_GPIOD, GPIO_PORTD_BASE}, GPIO_PIN_5}, | ||
| {{SYSCTL_PERIPH_GPIOD, GPIO_PORTD_BASE}, GPIO_PIN_4}}; | ||
| #endif | ||
|
|
||
|
|
||
| //------------------------------GLOBALS-------------------------------// | ||
| int status = PRE_INIT; | ||
| uint8_t active_pins = 0; | ||
| uint32_t *adc_buffer = (void *)0; | ||
| void (*adc_callback)(void) = (void *)0; | ||
|
|
||
|
|
||
| //--------------------------LOCAL_FUNCTIONS---------------------------// | ||
| /* If a module is not already enabled: enables it, then waits until it | ||
| * is responding as ready. */ | ||
| void init_module(uint32_t sysctl_module) { | ||
| if (SysCtlPeripheralReady(sysctl_module) == false) { | ||
| SysCtlPeripheralEnable(sysctl_module); | ||
| while (SysCtlPeripheralReady(sysctl_module) == false) | ||
| ; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| //-------------------------EXTERNAL_FUNCTIONS-------------------------// | ||
| /* Interrupt handler that needs to be configured in a module's prx file | ||
| * if the interrupt mode is used. | ||
| */ | ||
| void adc_irq_handler(void) { | ||
| /* Clear interrupt flag so we don't instantly return to the handler */ | ||
| ADCIntClear(ADC0_BASE, sequence_num); | ||
| ADCSequenceDataGet(ADC0_BASE, sequence_num, adc_buffer); | ||
| /* call the callback */ | ||
| adc_callback(); | ||
| } | ||
|
|
||
| enum adc_return adc_init_pins(enum adc_pin *pins, uint8_t num_pins, bool interrupt_mode) { | ||
| // adc_assert(status == PRE_INIT); | ||
| // adc_assert(num_pins < 9); | ||
| // adc_assert(pins != (void *)0); | ||
|
|
||
| active_pins = num_pins; | ||
|
|
||
| /* initialise ADC module */ | ||
| init_module(adc_sc_module); | ||
| ADCIntDisable(ADC0_BASE, sequence_num); | ||
|
|
||
| /* configure ADC module */ | ||
| ADCClockConfigSet(ADC0_BASE, adc_clock_config, adc_clock_div); | ||
| ADCReferenceSet(ADC0_BASE, adc_reference); | ||
|
|
||
| /* pin initialisation and configuration */ | ||
| for (int i = 0; i < num_pins; i++) { | ||
| /* initialise GPIO module */ | ||
| init_module(gpio_lut[pins[i]].port.sysctl); | ||
| /* configure ADC/GPIO pins */ | ||
| GPIOPinTypeADC(gpio_lut[pins[i]].port.base, gpio_lut[pins[i]].pin); | ||
| } | ||
|
|
||
| /* disable before configuring sequencer */ | ||
| ADCSequenceDisable(ADC0_BASE, sequence_num); | ||
|
|
||
| /* setup ADC sample sequencer, trigger manually in software */ | ||
| ADCSequenceConfigure(ADC0_BASE, sequence_num, | ||
| ADC_TRIGGER_PROCESSOR, 0); | ||
|
|
||
| /* configure each step of sequence to be an analog input source */ | ||
| int i = 0; | ||
| for (i = 0; i < num_pins-1; i++) { | ||
| ADCSequenceStepConfigure(ADC0_BASE, sequence_num, i, pins[i]); | ||
| } | ||
| /* last step is end of sequence, generate an interrupt here */ | ||
| ADCSequenceStepConfigure(ADC0_BASE, sequence_num, i, | ||
| pins[i] | ADC_CTL_IE | ADC_CTL_END); | ||
| /* never use this function, echronos handles irq registration */ | ||
| // ADCIntRegister(ADC0_BASE, sequence_num, adc_irq_handler); | ||
| ADCSequenceEnable(ADC0_BASE, sequence_num); | ||
| /* enable interrupts if in interrupt mode */ | ||
| if (interrupt_mode) { | ||
| ADCIntEnable(ADC0_BASE, sequence_num); | ||
| IntEnable(INT_ADC0SS0); | ||
| } | ||
| /* ready for capture */ | ||
| status = POST_INIT; | ||
| return ADC_SUCCESS; | ||
| } | ||
|
|
||
| enum adc_return adc_capture_interrupt(uint32_t *buffer, void (*callback)(void)) { | ||
| // adc_assert(status == POST_INIT); | ||
| // adc_assert(buffer != (void *)0); | ||
| // adc_assert(callback !=(void *)0); | ||
| adc_buffer = buffer; | ||
| adc_callback = callback; | ||
| ADCProcessorTrigger(ADC0_BASE, sequence_num); | ||
| return ADC_SUCCESS; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| uint32_t adc_capture_polling(uint32_t *buffer) { | ||
| // adc_assert(status == POST_INIT); | ||
| ADCProcessorTrigger(ADC0_BASE, sequence_num); | ||
| while (!ADCIntStatus(ADC0_BASE, sequence_num, false)) {}; | ||
| uint32_t num_samples = ADCSequenceDataGet(ADC0_BASE, sequence_num, buffer); | ||
| return num_samples; | ||
| } | ||
|
|
||
|
|
||
| enum adc_return adc_interrupt_disable() { | ||
| ADCIntDisable(ADC0_BASE, sequence_num); | ||
| IntDisable(INT_ADC0SS0); | ||
| return ADC_SUCCESS; | ||
| } | ||
|
|
||
| enum adc_return adc_interrupt_enable() { | ||
| ADCIntEnable(ADC0_BASE, sequence_num); | ||
| IntEnable(INT_ADC0SS0); | ||
| return ADC_SUCCESS; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be better to use something more portable like tmux