Skip to content

Commit 23f3b7d

Browse files
committed
seperation of I2C and SPI driver
1 parent 0c9b1a6 commit 23f3b7d

27 files changed

Lines changed: 500 additions & 290 deletions

Kbuild

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
EXTRA_CFLAGS := -I$(src)/aos_tmf8829_core_library/src
22
EXTRA_CFLAGS += -I$(src)
33
EXTRA_CFLAGS += -Wno-unused-function # -Wextra
4+
#EXTRA_CFLAGS += -DUSE_I2C
5+
EXTRA_CFLAGS += -DUSE_SPI
46
obj-$(CONFIG_SENSORS_TMF8829) += tmf8829.o
57
tmf8829-y = tmf8829_driver.o ./aos_tmf8829_core_library/src/tmf8829.o ams_i2c.o tmf8829_shim.o tmf8829_hex_interpreter.o

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ all:
1818
dtc -@ -I dts -O dtb -o ./arch/arm/boot/dts/tmf8829-overlay-fpc-polled.dtbo ./arch/arm/boot/dts/tmf8829-overlay-fpc-polled.dts
1919
dtc -@ -I dts -O dtb -o ./arch/arm/boot/dts/tmf8829-overlay-fpc-spi.dtbo ./arch/arm/boot/dts/tmf8829-overlay-fpc-spi.dts
2020
dtc -@ -I dts -O dtb -o ./arch/arm/boot/dts/tmf8829-overlay-fpc-spi-polled.dtbo ./arch/arm/boot/dts/tmf8829-overlay-fpc-spi-polled.dts
21-
21+
dtc -@ -I dts -O dtb -o ./arch/arm/boot/dts/tmf8829-overlay-fpc-spi-polled-fusion.dtbo ./arch/arm/boot/dts/tmf8829-overlay-fpc-spi-polled-fusion.dts
22+
2223
modules:
2324
$(MAKE) -C $(LINUX_SRC) M=$$PWD $@
2425

README.md

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,65 @@
33
## Description
44

55
This file describes the installation of the tmf8829 linux reference driver, and how to use it.
6+
There is also a description for using python files contained in the tmf8829_zeromq_server_linux folder.
7+
8+
Information regarding the TMF8829 time of flight device can be found at:
9+
https://ams-osram.com/products/sensor-solutions/direct-time-of-flight-sensors-dtof/ams-tmf8829-48x32-multi-zone-time-of-flight-sensor
610

711
### Compilation
812

913
The compilation was done with the ams-Osram provided image bookworm_4v0.
1014
Linux version 6.1.73-ams #1 Mon Apr 22 19:32:02 BST 2024 2024 armv6l
1115

16+
The reference driver could be build as I2C or SPI driver.
17+
See EXTRA_CFLAGS in Kbuild.
18+
For I2C use: EXTRA_CFLAGS += -DUSE_I2C
19+
For SPI use: EXTRA_CFLAGS += -DUSE_SPI
20+
21+
For compilation on the bookworm image use the command:
22+
- make CONFIG_SENSORS_TMF8829=m
23+
24+
For compilation on an other image it is required to adapt the linux source path.
25+
The linux sources could be found in the folder "/usr/src".
26+
The LINUX_SRC path in the file Makefile must be adapted, or the LINUX_SRC path must be specified in the command.
27+
28+
Examples:
29+
- make CONFIG_SENSORS_TMF8829=m LINUX_SRC=/usr/src/linux-$(uname -r)
30+
- make CONFIG_SENSORS_TMF8829=m LINUX_SRC=/usr/src/linux-headers-$(uname -r)
31+
- make CONFIG_SENSORS_TMF8829=m LINUX_SRC=/usr/src/linux-6.1.73-ams
32+
33+
### Linux Driver Sources
34+
35+
The Linux Driver Sources could be found on GITHUB:
36+
37+
- https://github.com/ams-OSRAM/tmf8829_driver_linux
38+
39+
with
40+
41+
- git clone https://github.com/ams-OSRAM/tmf8829_driver_linux.git
42+
43+
or from the TMF8829 product site.
44+
1245
## Files
1346

14-
Overlay Files
47+
Overlay Files <br>
1548
The device tree overlay files for the tmf8829 prototyped on the Raspberry Pi zero.
49+
<br>
1650
- tmf8829-overlay-fpc.dts
1751
evm configuration with flex printed circuit, EN gpio and INT gpio, I2C
52+
<br>
1853
- tmf8829-overlay-fpc-polled.dts
1954
evm configuration with flex printed circuit, EN gpio and INT register polled, I2C
55+
<br>
2056
- tmf8829-overlay-fpc-spi.dts
2157
evm configuration with flex printed circuit, EN gpio and INT gpio, SPI
58+
<br>
2259
- tmf8829-overlay-fpc-spi-polled.dts
2360
evm configuration with flex printed circuit, EN gpio and INT register polled, SPI
2461

2562
Module File
26-
- tmf8829.ko
63+
- tmf8829.ko for SPI
64+
- tmf8829.ko for I2C
2765

2866
ams Raspberry USB Sensorbridge
2967
- ams-usb-sensorbridge.service
@@ -66,6 +104,7 @@ Configuration of Raspberry Pi zero:
66104
- tmf8829-overlay-fpc-spi.dtbo for spi communication
67105
- tmf8829-overlay-fpc-polled.dtbo for i2c communication and int register polling
68106
- tmf8829-overlay-fpc-spi-polled.dtbo for spi communication and int register polling
107+
- tmf8829-overlay-fpc-spi-polled-fusion.dts special overlay file
69108

70109
- Hex File ( if required )
71110

@@ -91,14 +130,18 @@ Configuration of Raspberry Pi zero:
91130
<br>or
92131
- ./tmf8829_install_spi_polled_int.sh
93132

94-
7. Optional:<br> If the python zmq server sources will be installed
133+
7. for I2C driver:
134+
- open /boot/firmware/config.txt
135+
uncomment line dtoverlay=gpio-ir-tx,gpio_pin=25
136+
137+
8. Optional:<br> If the python zmq server sources will be installed
95138
and the server should be started at boot time, enable the zmq service.
96139

97140
- systemctl enable tmf8829_zmq_server.service
98141

99-
8. sync
142+
9. sync
100143

101-
9. reboot (reboot system)
144+
10. reboot (reboot system)
102145

103146
## General commands on the Raspberry Pi
104147

@@ -143,11 +186,7 @@ Configuration of Raspberry Pi zero:
143186

144187
- ps -ef
145188

146-
8. Makefile command for TMF8829
147-
148-
- make CONFIG_SENSORS_TMF8829=m
149-
150-
9. The overlay file could be changed
189+
8. The overlay file could be changed
151190

152191
- copy overlay file to boot directory
153192

@@ -167,24 +206,25 @@ Configuration of Raspberry Pi zero:
167206

168207
- echo "dtoverlay=tmf8829-overlay" >> /boot/firmware/config.txt
169208

170-
10. Change and see log level
209+
9. Change and see log level
171210

172211
- echo <level> > /proc/sys/kernel/printk
173212
- cat /proc/sys/kernel/printk
174213

175-
11. See temperature and cpu frequency
214+
10. See temperature and cpu frequency
176215

177216
- vcgencmd measure_temp
178217
- vcgencmd measure_clock arm
179218

180-
12. Change raspberry configuration
219+
11. Change raspberry configuration
181220

182221
- sudo raspi-config
183222

184-
13. see the running services
223+
12. see the running services
185224

186225
- systemctl
187-
14. start / stop the running tmf8829 zmq service
226+
227+
13. start / stop the running tmf8829 zmq service
188228

189229
- systemctl start tmf8829_zmq_server.service
190230
- systemctl stop tmf8829_zmq_server.service
@@ -202,7 +242,9 @@ https://www.raspberrypi.com/documentation/computers/raspberry-pi.html
202242

203243
## System File System
204244

205-
- I2C Bus 0 (fpc): /sys/class/i2c-adapter/i2c-0/0-0041/
245+
File System location:
246+
- I2C Driver: I2C Bus 0 (fpc): /sys/class/i2c-adapter/i2c-0/0-0041/
247+
- SPI Driver: SPI Dev 0: /sys/class/spi_master/spi0/spi0.0/
206248

207249
### Common Attributes (tmf8829_common)
208250

@@ -366,7 +408,7 @@ Attributes:
366408
- FrameID:
367409
- TMF8829_COM_RESULT__measurement_res_frame 0xAA /**< measurement result frame */
368410
- TMF8829_COM_RESULT__measurement_hist_frame 0xBB /**< measurement histogram frame */
369-
- TMF8829_COM_RESULT__measurement_header 0xFD /**< measurement frame header only; for debug only should never occur in result frame */
411+
- TMF8829_COM_RESULT__measurement_header 0xFD /**< measurement frame header only; for debug only should never occur in result frame */
370412
- TMF8829_COM_RESULT__error_frame 0xFE /**< error frame */
371413
- TMF8829_COM_RESULT__no_frame 0xFF /**< no frame / unhandled interrupt */
372414
- The clock correction factor is only available for result frames in Q1.15 numbering format.
@@ -439,7 +481,7 @@ The logger description README.md in the folder /home/ams/tmf8829_zeromq_server_l
439481
python ./tmf8829_zeromq_client.py
440482
```
441483

442-
443484
### GUI
444485

445486
The TMF8829 EVM GUI could be used to see the results on a pc.
487+
This software could be downloaded from the product site. See section "Software".

ReleaseNotes.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
Release Notes TMF8829 Linux Driver
33
===================================================
44
---------------------------------------------------
5+
- 2v4
6+
---------------------------------------------------
7+
- separation of I2C and SPI driver.
8+
In Kbuild the flag USE_I2C or DUSE_SPI is used
9+
- In probe function, the Irq Error is not reported anymore.
10+
This error does not have an impact on the driver and is misleading.
11+
---------------------------------------------------
12+
- 2v3
13+
---------------------------------------------------
14+
- in probe do tof_register_spi_driver earlier.
15+
- Stop Measurement check for standby-timed mode
16+
- powerup_select to RAM option at tmf8829DownloadFirmware
17+
- wakeup with wait time and cpu ready check
18+
- Int polling mode fix
19+
---------------------------------------------------
520
- 2v2
621
---------------------------------------------------
722
- new hex file

aos_tmf8829_core_library/src/tmf8829.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ int8_t tmf8829BootloaderCmdI2cOff ( tmf8829Driver * driver )
496496
}
497497

498498
// execute command to set the RAM address pointer for RAM read/writes
499-
static int8_t tmf8829BootloaderSetRamAddr ( tmf8829Driver * driver, uint32_t addr )
499+
int8_t tmf8829BootloaderSetRamAddr ( tmf8829Driver * driver, uint32_t addr )
500500
{
501501
driver->dataBuffer[0] = TMF8829_COM_BL_CMD_STAT_ADDR_RAM;
502502
driver->dataBuffer[1] = 4; // payload
@@ -510,7 +510,7 @@ static int8_t tmf8829BootloaderSetRamAddr ( tmf8829Driver * driver, uint32_t add
510510
}
511511

512512
// writes to both CPU RAMs in parallel
513-
static int8_t tmf8829BootloaderWriteRamBoth ( tmf8829Driver * driver, uint8_t len )
513+
int8_t tmf8829BootloaderWriteRamBoth ( tmf8829Driver * driver, uint8_t len )
514514
{
515515
driver->dataBuffer[0] = TMF8829_COM_BL_CMD_STAT_W_RAM_BOTH;
516516
driver->dataBuffer[1] = len; // payload
@@ -535,13 +535,34 @@ static int8_t tmf8829BootloaderWriteFifoBoth ( tmf8829Driver * driver, uint32_t
535535
}
536536

537537
//to start the down-loaded measurement application
538-
static int8_t tmf8829BootloaderStartRamApp ( tmf8829Driver * driver )
538+
int8_t tmf8829BootloaderStartRamApp ( tmf8829Driver * driver )
539539
{
540540
driver->dataBuffer[0] = TMF8829_COM_BL_CMD_STAT_START_RAM_APP;
541541
txReg( driver, driver->i2cSlaveAddress, TMF8829_COM_REG_CMD_STAT, 1, driver->dataBuffer );
542542
return tmf8829CheckRegister( driver, TMF8829_COM_REG_APP_ID, TMF8829_COM_APP_ID__application, 1, BL_CMD_START_RAM_APP_MS );
543543
}
544544

545+
int8_t tmf8829BootloaderStartRamAppAndPowerOn ( tmf8829Driver * driver )
546+
{
547+
int8_t stat = BL_SUCCESS_OK;
548+
stat = tmf8829BootloaderStartRamApp( driver );
549+
if ( stat == BL_SUCCESS_OK )
550+
{
551+
if ( driver->logLevel >=TMF8829_LOG_LEVEL_INFO )
552+
{
553+
PRINT_STR( "Ram started" );
554+
PRINT_LN( );
555+
}
556+
// Enable Register with RAM in powerup_select
557+
driver->dataBuffer[0] = 0; // clear before reading
558+
rxReg( driver, driver->i2cSlaveAddress, ENABLE, 1, driver->dataBuffer );
559+
driver->dataBuffer[0] = driver->dataBuffer[0] & ( ~TMF8829_ENABLE__powerup_select__MASK ); // clear powerup_select
560+
driver->dataBuffer[0] = driver->dataBuffer[0] | ( ENABLE__powerup_select__RAM << ENABLE__powerup_select__SHIFT ); // select RAM
561+
txReg( driver, driver->i2cSlaveAddress, ENABLE, 1, driver->dataBuffer ); // set PON bit in enable register
562+
}
563+
return stat;
564+
}
565+
545566
int8_t tmf8829DownloadFirmware ( tmf8829Driver * driver, uint32_t imageStartAddress, const uint8_t * image, int32_t imageSizeInBytes, uint8_t useFifo )
546567
{
547568
uint32_t idx = 0;
@@ -726,7 +747,7 @@ static void tmf8829ClockCorrectionAddPair ( tmf8829Driver * driver, uint32_t hos
726747
PRINT_LN( );
727748
}
728749

729-
}
750+
}
730751

731752
int8_t tmf8829ReadDeviceInfo ( tmf8829Driver * driver )
732753
{

aos_tmf8829_core_library/src/tmf8829.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,20 @@ int8_t tmf8829BootloaderCmdSpiOff( tmf8829Driver * driver );
313313
*/
314314
int8_t tmf8829BootloaderCmdI2cOff( tmf8829Driver * driver );
315315

316+
/** @brief Function set ram address to write
317+
* @param driver ... pointer to an instance of the tmf8829 driver data structure
318+
* @param addr ..... ram address to write
319+
* @return Function returns APP_SUCCESS_OK if successfully set ram address, else it returns an error APP_ERROR_TIMEOUT
320+
*/
321+
int8_t tmf8829BootloaderSetRamAddr ( tmf8829Driver * driver, uint32_t addr );
322+
323+
/** @brief Function writes data to both CPU RAMs in parallel
324+
* @param driver ... pointer to an instance of the tmf8829 driver data structure
325+
* @param len ...... number of bytes to write
326+
* @return Function returns APP_SUCCESS_OK if successfully write data to ram, else it returns an error APP_ERROR_TIMEOUT
327+
*/
328+
int8_t tmf8829BootloaderWriteRamBoth ( tmf8829Driver * driver, uint8_t len );
329+
316330
// ------------------------------- convenience functions --------------------------------------------
317331

318332
/** @brief Convert 4 bytes in little endian format into an uint32_t
@@ -335,6 +349,18 @@ void tmf8829SetUint16( uint16_t value, uint8_t * data );
335349

336350
// ------------------------------- bootloader functions --------------------------------------------
337351

352+
/** @brief Function starts ram application
353+
* @param driver ... pointer to an instance of the tmf8829 driver data structure
354+
* @return Function returns APP_SUCCESS_OK if successfully start ram application, else it returns an error APP_ERROR_*
355+
*/
356+
int8_t tmf8829BootloaderStartRamApp ( tmf8829Driver * driver );
357+
358+
/** @brief Function starts ram application and enable Register with RAM in powerup_select
359+
* @param driver ... pointer to an instance of the tmf8829 driver data structure
360+
* @return Function returns APP_SUCCESS_OK if successfully start ram application, else it returns an error APP_ERROR_*
361+
*/
362+
int8_t tmf8829BootloaderStartRamAppAndPowerOn ( tmf8829Driver * driver );
363+
338364
/** @brief Function to download the firmware image that was linked against the firmware (tmf8829_image.{h,c} files)
339365
* The function tmf8829BootloaderStartRamApp is executed after successful download.
340366
* powerup_select in the ENABLE register to RAM
@@ -350,7 +376,6 @@ int8_t tmf8829DownloadFirmware( tmf8829Driver * driver, uint32_t imageStartAddre
350376
// ------------------------------- application functions --------------------------------------------
351377

352378
// Application functions are only available after a successful firmware download and a successful start of the ram app.
353-
354379
/** @brief Function reads complete device information
355380
* @param driver ... pointer to an instance of the tmf8829 driver data structure
356381
* @return Function returns APP_SUCCESS_OK if successfully read the complete device information, else it returns an error APP_ERROR_*
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
************************************************************************************
3+
* Copyright (c) [2025] ams-OSRAM AG *
4+
* *
5+
* SPDX-License-Identifier: GPL-2.0 OR MIT *
6+
* *
7+
* For the full license texts, see LICENSES-GPL-2.0.txt or LICENSES-MIT.TXT. *
8+
************************************************************************************
9+
*/
10+
11+
/* Definitions for tmf8829 time-of-flight sensor from ams AG
12+
*
13+
* Compile:
14+
* dtc -@ -I dts -O dtb -o tmf8829-overlay-fpc_spi_polled.dtbo tmf8829-overlay-fpc_spi_polled.dts
15+
*/
16+
17+
/dts-v1/;
18+
/plugin/;
19+
20+
/ {
21+
compatible = "brcm,bcm2835","brcm,bcm2708","brcm,bcm2709";
22+
23+
24+
fragment@0 {
25+
target = <&gpio>;
26+
__overlay__ {
27+
tmf8829_pins: tmf8829_pins {
28+
brcm,pins = <16>; /*enable (CAM_IO1->GPIO40)*/
29+
brcm,function = <1>; /*enable output*/
30+
brcm,pull = <0>; /*enable pull-down on CE*/
31+
};
32+
};
33+
};
34+
35+
fragment@1 {
36+
target = <&spidev0>;
37+
__overlay__ {
38+
status = "disabled";
39+
};
40+
};
41+
fragment@2 {
42+
target = <&spidev1>;
43+
__overlay__ {
44+
status = "disabled";
45+
};
46+
};
47+
48+
fragment@3 {
49+
target = <&spi0>;
50+
__overlay__ {
51+
#address-cells = <1>;
52+
#size-cells = <0>;
53+
status = "okay";
54+
55+
tmf8829_spi@0 {
56+
compatible = "ams,tmf8829_spi";
57+
reg = <0>;
58+
spi-max-frequency = <5000000>;
59+
60+
pinctrl-names = "default";
61+
pinctrl-0 = <&tmf8829_pins>;
62+
tof,tof_poll_period = <0xA>; /*poll period (100 usec)*/
63+
enable-gpios = <&gpio 16 0>; /* CAM_GPIO1 on header*/
64+
65+
};
66+
};
67+
};
68+
69+
};
70+

0 commit comments

Comments
 (0)