Skip to content

feat(sensor): Added sensor hal modules#39

Merged
RoshanMGanesh merged 3 commits intodevelopfrom
feat/sensor-hal
May 3, 2026
Merged

feat(sensor): Added sensor hal modules#39
RoshanMGanesh merged 3 commits intodevelopfrom
feat/sensor-hal

Conversation

@RoshanMGanesh
Copy link
Copy Markdown
Collaborator

@RoshanMGanesh RoshanMGanesh commented Apr 27, 2026

Summary

Implements the full Sensor HAL module for Sprint 2. Adds sensor_hal.c and sensor_hal.h with ADC reads for battery temperature (LM35, CH0), motor temperature (LM35, CH1), battery current (ACS712-20A, CH2), battery voltage (resistor divider, CH3), and throttle position (potentiometer, CH4).

Type of Change

  • 🆕 New feature / user story
  • 🐛 Bug fix
  • ♻️ Refactor (no behaviour change)
  • 📝 Documentation only
  • 🔧 CI/CD or tooling change
  • 🔒 Security fix

Related Issue

Closes #23 #22 #24 #25 #26 #27 #28

Changes Made

  • Added core/src/sensor_hal.c - full implementation of all 8 sensor read functions plus sensor_init(), sensor_read_all(), sensor_enable_i2c_temp() (stub), and sensor_get_temp_backend()
  • Added core/inc/sensor_hal.h - public interface with Doxygen comments for every function, including Sprint 5 I2C preparation stubs
  • Updated drivers/STM32_HAL/stm32_stubs.c - added stub implementations for all HAL GPIO, ADC, and timer functions used by the sensor module
  • Added tests/test_sensor_hal.c - 22 unit tests covering all sensor read functions, boundary conditions, null pointer guards, ADC channel isolation, and GPIO debounce logic
  • Added tests/mocks/mock_stm32_hal_adc.c/.h - full mock with per-channel value injection, start error, and poll timeout injection
  • Added tests/mocks/mock_stm32_hal_gpio.c/.h - full mock with per-pin state control and mock_hal_set_tick() for debounce testing
  • Added tests/mocks/mock_stm32_hal_tim.c/.h - mock with encoder count injection, ARR/CCR1 access, and PWM start error injection

How to Test This PR

  1. Clone the branch: git checkout feat/sensor-hal
  2. Build the test suite: cd tests && mkdir -p build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Debug && make

Testing Done by Author

  • Unit tests written for new/changed code
  • All existing tests pass locally (cd Tests/build && ./test_runner → 0 Failures)
  • Cppcheck passes locally (cppcheck --error-exitcode=1 -I core/Inc core/src/)
  • Code compiled successfully (cmake --build build)
  • Tested in Wokwi simulation (if applicable)
  • UART output verified (if applicable)
  • No new compiler warnings (-Wall -Wextra clean)

Code Quality Checklist

  • Code follows naming conventions from 06_CODING_STANDARDS.md
  • All public functions have Doxygen-style comments (@brief, @param, @retval)
  • No magic numbers — all constants are in ev_config.h
  • All function parameters are validated (null checks where applicable)
  • Return values of all called functions are checked
  • All switch statements have a default case
  • All if/for/while blocks use { braces even for single lines

Documentation

  • README.md updated if new setup steps are needed
  • Inline /* TODO: */ comments added for any deferred work

Reviewer checklist:

  • Code logic is correct and matches the linked issue requirements
  • Tests are meaningful (not just "assert(1 == 1)")
  • No obvious security or safety issues
  • Comments are clear and accurate

@RoshanMGanesh RoshanMGanesh marked this pull request as ready for review May 3, 2026 17:24
@RoshanMGanesh RoshanMGanesh merged commit f3708d4 into develop May 3, 2026
3 checks passed
@Rohith-Kalarikkal Rohith-Kalarikkal deleted the feat/sensor-hal branch May 3, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants