Skip to content
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

ARM I2C driver not implemented for KINETIS MCU's (i.e. Teensy 3.2/3.5/3.6/LC) #7574

Closed
1 of 4 tasks
St0RM53 opened this issue Dec 9, 2019 · 6 comments · Fixed by #7591
Closed
1 of 4 tasks

ARM I2C driver not implemented for KINETIS MCU's (i.e. Teensy 3.2/3.5/3.6/LC) #7574

St0RM53 opened this issue Dec 9, 2019 · 6 comments · Fixed by #7591

Comments

@St0RM53
Copy link

St0RM53 commented Dec 9, 2019

The I2C driver used for OLED functionality does not support KINETIS ARM microcontrollers.

Feature Request Type

  • Core functionality
  • Add-on hardware support (eg. audio, RGB, OLED screen, etc.)
  • Alteration (enhancement/optimization) of existing feature(s)
  • New behavior

Description

I have been waiting to implement this functionality on my finished keyboard i made about 3 months ago. This has been discussed on the discord server and while some process was made, the driver has no proper definitions to compile and work with the Chibios hal driver.

Setting the following in:
mcuconf.h

#define KINETIS_I2C_USE_I2C1                TRUE
#define KINETIS_I2C_I2C1_PRIORITY           4

config.h

#define USE_I2CV1
#define I2C_DRIVER I2CD1
#define I2C1_OPMODE 1
#define I2C1_CLOCK_SPEED 100000
#define I2C1_DUTY_CYCLE 1

#define I2C1_SCL_BANK GPIOC
#define I2C1_SDA_BANK GPIOC
#define I2C1_SCL 10
#define I2C1_SDA 11

will result in the following compilation output:

tnf@tnf-VirtualBox:~/Desktop/github/qmk_firmware$ make lilith101:default
QMK Firmware 0.7.97
Making lilith101 with keymap default

arm-none-eabi-gcc (15:6.3.1+svn253039-1build1) 6.3.1 20170620
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Size before:
   text	   data	    bss	    dec	    hex	filename
      0	  34376	      0	  34376	   8648	.build/lilith101_default.hex

Compiling: drivers/arm/i2c_master.c                                                                In file included from <command-line>:0:0:
./keyboards/lilith101/config.h:120:26: error: excess elements in struct initializer [-Werror]
 #define I2C1_CLOCK_SPEED 100000
                          ^
drivers/arm/i2c_master.c:38:5: note: in expansion of macro 'I2C1_CLOCK_SPEED'
     I2C1_CLOCK_SPEED,
     ^~~~~~~~~~~~~~~~
./keyboards/lilith101/config.h:120:26: note: (near initialization for 'i2cconfig')
 #define I2C1_CLOCK_SPEED 100000
                          ^
drivers/arm/i2c_master.c:38:5: note: in expansion of macro 'I2C1_CLOCK_SPEED'
     I2C1_CLOCK_SPEED,
     ^~~~~~~~~~~~~~~~
./keyboards/lilith101/config.h:121:25: error: excess elements in struct initializer [-Werror]
 #define I2C1_DUTY_CYCLE 1
                         ^
drivers/arm/i2c_master.c:39:5: note: in expansion of macro 'I2C1_DUTY_CYCLE'
     I2C1_DUTY_CYCLE,
     ^~~~~~~~~~~~~~~
./keyboards/lilith101/config.h:121:25: note: (near initialization for 'i2cconfig')
 #define I2C1_DUTY_CYCLE 1
                         ^
drivers/arm/i2c_master.c:39:5: note: in expansion of macro 'I2C1_DUTY_CYCLE'
     I2C1_DUTY_CYCLE,
     ^~~~~~~~~~~~~~~
In file included from ./lib/chibios/os/hal/include/hal_pal.h:129:0,
                 from ./lib/chibios/os/hal/include/hal.h:124,
                 from drivers/arm/i2c_master.h:28,
                 from drivers/arm/i2c_master.c:28:
drivers/arm/i2c_master.c: In function 'i2c_init':
drivers/arm/i2c_master.c:66:44: error: 'PAL_MODE_STM32_ALTERNATE_OPENDRAIN' undeclared (first use in this function)
     palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
                                            ^
./lib/chibios-contrib/os/hal/ports/KINETIS/LLD/hal_pal_lld.h:394:36: note: in definition of macro 'pal_lld_setpadmode'
     _pal_lld_setpadmode(port, pad, mode)
                                    ^~~~
drivers/arm/i2c_master.c:66:5: note: in expansion of macro 'palSetPadMode'
     palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
     ^~~~~~~~~~~~~
drivers/arm/i2c_master.c:66:44: note: each undeclared identifier is reported only once for each function it appears in
     palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
                                            ^
./lib/chibios-contrib/os/hal/ports/KINETIS/LLD/hal_pal_lld.h:394:36: note: in definition of macro 'pal_lld_setpadmode'
     _pal_lld_setpadmode(port, pad, mode)
                                    ^~~~
drivers/arm/i2c_master.c:66:5: note: in expansion of macro 'palSetPadMode'
     palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
     ^~~~~~~~~~~~~
In file included from <command-line>:0:0:
drivers/arm/i2c_master.c: In function 'i2c_start':
./keyboards/lilith101/config.h:117:20: error: 'I2CD1' undeclared (first use in this function)
 #define I2C_DRIVER I2CD1
                    ^
drivers/arm/i2c_master.c:76:15: note: in expansion of macro 'I2C_DRIVER'
     i2cStart(&I2C_DRIVER, &i2cconfig);
               ^~~~~~~~~~
drivers/arm/i2c_master.c: In function 'i2c_transmit':
./keyboards/lilith101/config.h:117:20: error: 'I2CD1' undeclared (first use in this function)
 #define I2C_DRIVER I2CD1
                    ^
drivers/arm/i2c_master.c:82:15: note: in expansion of macro 'I2C_DRIVER'
     i2cStart(&I2C_DRIVER, &i2cconfig);
               ^~~~~~~~~~
drivers/arm/i2c_master.c: In function 'i2c_receive':
./keyboards/lilith101/config.h:117:20: error: 'I2CD1' undeclared (first use in this function)
 #define I2C_DRIVER I2CD1
                    ^
drivers/arm/i2c_master.c:89:15: note: in expansion of macro 'I2C_DRIVER'
     i2cStart(&I2C_DRIVER, &i2cconfig);
               ^~~~~~~~~~
drivers/arm/i2c_master.c: In function 'i2c_writeReg':
./keyboards/lilith101/config.h:117:20: error: 'I2CD1' undeclared (first use in this function)
 #define I2C_DRIVER I2CD1
                    ^
drivers/arm/i2c_master.c:96:15: note: in expansion of macro 'I2C_DRIVER'
     i2cStart(&I2C_DRIVER, &i2cconfig);
               ^~~~~~~~~~
drivers/arm/i2c_master.c: In function 'i2c_readReg':
./keyboards/lilith101/config.h:117:20: error: 'I2CD1' undeclared (first use in this function)
 #define I2C_DRIVER I2CD1
                    ^
drivers/arm/i2c_master.c:110:15: note: in expansion of macro 'I2C_DRIVER'
     i2cStart(&I2C_DRIVER, &i2cconfig);
               ^~~~~~~~~~
drivers/arm/i2c_master.c: In function 'i2c_stop':
./keyboards/lilith101/config.h:117:20: error: 'I2CD1' undeclared (first use in this function)
 #define I2C_DRIVER I2CD1
                    ^
drivers/arm/i2c_master.c:115:32: note: in expansion of macro 'I2C_DRIVER'
 void i2c_stop(void) { i2cStop(&I2C_DRIVER); }
                                ^~~~~~~~~~
cc1: all warnings being treated as errors
 [ERRORS]
 | 
 | 
 | 
tmk_core/rules.mk:377: recipe for target '.build/obj_lilith101_default/i2c_master.o' failed
make[1]: *** [.build/obj_lilith101_default/i2c_master.o] Error 1
Makefile:560: recipe for target 'lilith101:default' failed
make: *** [lilith101:default] Error 1
tnf@tnf-VirtualBox:~/Desktop/github/qmk_firmware$ Make finished with errors

Default values for OPMODE_I2C and STD_DUTY_CYCLE are missing (that's why they are set in the config file), and USE_I2CV1 should be defined by the driver.

This is the furthest i could get with my skills.
Functionality is already supported in Chibios.
Hopefully the community can implement this properly since it will open up the functionality of QMK even further:)
I can provide hardware testing since it is already build and used daily.

@yulei
Copy link
Contributor

yulei commented Dec 9, 2019

you can move #define USE_I2CV1 from mcuconf.h to config.h which could bypass this issue.
https://github.com/qmk/qmk_firmware/blob/master/keyboards/matrix/noah/config.h

And after pr #7526 was merged, you can add the KINETIS support easier.

@drashna
Copy link
Member

drashna commented Dec 9, 2019

Also need this for the input club keyboards, as they use a custom i2c implementation but need the i2c_master driver support to switch off of uGFX

@St0RM53
Copy link
Author

St0RM53 commented Dec 9, 2019

you can move #define USE_I2CV1 from mcuconf.h to config.h which could bypass this issue.
https://github.com/qmk/qmk_firmware/blob/master/keyboards/matrix/noah/config.h

And after pr #7526 was merged, you can add the KINETIS support easier.

It was already on config.h along with #define I2C_DRIVER I2CD1, i just copied and pasted on the wrong field while writing the post. I edited it, sorry.

@zvecr
Copy link
Member

zvecr commented Dec 9, 2019

There is a small amount of change required outside of USE_I2CV1 to get this working, mostly due to the fact the ChibiOS-contrib hal port is a tad inconsistent. I've opened #7591 to cover the changes, but it has a few dependencies to get in first.

@St0RM53
Copy link
Author

St0RM53 commented Dec 10, 2019

Thanks a lot @zvecr. I will wait until it's ready and then test :)

@stale
Copy link

stale bot commented Mar 9, 2020

This issue has been automatically marked as stale because it has not had activity in the last 90 days. It will be closed in the next 30 days unless it is tagged properly or other activity occurs.
For maintainers: Please label with bug, in progress, on hold, discussion or to do to prevent the issue from being re-flagged.

@stale stale bot added the stale Issues or pull requests that have become inactive without resolution. label Mar 9, 2020
@stale stale bot removed the stale Issues or pull requests that have become inactive without resolution. label Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants