-
Notifications
You must be signed in to change notification settings - Fork 7.7k
drivers: sensor: microchip: mtch9010 Added MTCH9010 Device Support #91812
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
base: main
Are you sure you want to change the base?
drivers: sensor: microchip: mtch9010 Added MTCH9010 Device Support #91812
Conversation
If possible, could we add this for v4.2 |
#define MTCH9010_OPERATING_MODE_INIT(inst) \ | ||
COND_CODE_1(DT_INST_ENUM_HAS_VALUE(inst, mtch9010_operating_mode,\ | ||
capacitive), (MTCH9010_CONDUCTIVE), (MTCH9010_CAPACITIVE)) |
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.
unless i'm mistaken:
#define MTCH9010_OPERATING_MODE_INIT(inst) \ | |
COND_CODE_1(DT_INST_ENUM_HAS_VALUE(inst, mtch9010_operating_mode,\ | |
capacitive), (MTCH9010_CONDUCTIVE), (MTCH9010_CAPACITIVE)) | |
#define MTCH9010_OPERATING_MODE_INIT(inst) \ | |
COND_CODE_1(DT_INST_ENUM_HAS_VALUE(inst, mtch9010_operating_mode,\ | |
capacitive), (MTCH9010_CAPACITIVE), (MTCH9010_CONDUCTIVE)) |
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.
I seem to remember a test error before I swapped it ... I'll look at it again
gpio_pin_set_dt(&config->enableUARTLine, GPIO_OUTPUT_LOW); | ||
} else { | ||
gpio_pin_set_dt(&config->enableUARTLine, GPIO_OUTPUT_HIGH); |
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.
copy-paste error from previous block
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.
Ah, I see. UART EN is active LOW. Clarified intention in comments
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.
no the issue is basically the same thing @msalau commented on. You want to be controlling enableCFGLine here, not enableUARTLine??
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.
Thanks - I think I see the issue now
{ | ||
/* Note: nRESET is handled in device reset function */ | ||
int rtn = 0; | ||
|
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.
you're missing gpio_pin_configure_dt steps for the enableUARTLine and enableCFGLine output pins
{ | ||
int ret = 0; | ||
const struct mtch9010_config_t *config = dev->config; | ||
struct mtch9010_data_t *devData = dev->data; |
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.
no camel case please -- apply everywhere in the PR
https://docs.zephyrproject.org/latest/contribute/style/code.html#:~:text=Use%20snake%20case%20for%20code%20and%20variables.
val->val1 = data->heartbeatErrorState; | ||
break; | ||
} | ||
default: { |
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.
you're missing SENSOR_CHAN_MTCH9010_MEAS_RESULT_AND_DELTA
case?
.reference = MTCH9010_REF_VAL_INIT(inst), \ | ||
.threshold = DT_INST_PROP(inst, mtch9010_detect_value), \ | ||
.heartbeatErrorState = false, \ | ||
.lastResult = {0, 0}}; \ |
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.
lastWake also needs to be initialized to zero to not have issues w/ first sample reading
mtch9010_command_send(uartDev, config, tBuffer); | ||
|
||
#ifdef CONFIG_MTCH9010_LOCK_ON_STARTUP | ||
mtch9010_lock_device(dev); |
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.
undeclared function? did you mean mtch9010_lock_settings?
/* Keep LOW until ready to configure */ | ||
gpio_pin_configure_dt(&config->lockLine, GPIO_OUTPUT | GPIO_OUTPUT_INIT_HIGH); |
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.
comment doesn't match the code
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.
Comment is incorrect - fixed
tests/drivers/sensor/mtch9010/test_configs/data_format/current.overlay
Outdated
Show resolved
Hide resolved
cf24bb0
to
e4ac4a3
Compare
@kartben I'm looking at the twister failures, and it doesn't seem related to my PR, as I don't utilize with the file system. Can you confirm or rerun/ignore that twister error? |
yep, had nothing to do with you, and fixed now :) |
data->last_heartbeat = k_uptime_get(); | ||
|
||
/* Wait for boot-up */ | ||
k_msleep(CONFIG_MTCH9010_BOOT_TIME_MS); |
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.
Just highlighting that this will delay boot up process for all.
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.
Unfortunately, things stop working when I remove this delay. I have some theories, but for now, I'd like to keep this.
LOG_INST_DBG(config->log, "UART setup not enabled"); | ||
|
||
#ifdef CONFIG_MTCH9010_LOCK_ON_STARTUP | ||
BUILD_ASSERT(true, "MTCH9010_LOCK_ON_STARTUP cannot be set without UART enabled"); |
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.
Location of this BUILD_ASSERT()
is somewhat strange to me. It is not a part of the initialization routine. I think it should be closer to MTCH9010_DEFINE()
and be checked at build time.
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.
Moved assertion to define section 👍
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.
Please do not resolve comments. This is for the reviewers to do
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.
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.
My bad - thanks for letting me know
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.
The BUILD_ASSERT keeps causing issues, and since this is an optional feature anyway, I've removed the BUILD_ASSERT.
511c14e
to
3b46797
Compare
Looks like everything is good to go on our side 👍 Local test bench is functioning as expected |
I am marking it as tentative for 4.2 but my guess is that it will be tight as it is quite a significant PR and it will take time for reviewers to go through it. Thanks! |
Fixed double interrupt setup |
ba2ea80
to
8c97c6d
Compare
Removed BUILD_ASSERT due to persistent issues with logic. (System Lock does not affect core functionality - is optional) |
8c97c6d
to
2eeef0d
Compare
Fixed missing binding in yaml file |
Just for clarification - the single SonarQube issue (init complexity > 25) is not a blocker, correct? I can try to rework init down to <25, but I think it would be pretty tricky. |
Is UART mandatory for this driver? If mandatory: UART check should not be optional during initialization. Also asserting the UART configuration at build time may be a good idea. I.e. checking that speed is 38400, parity is None and 8 bits mode. If optional: A separate binding is needed to not require an UART bus. |
Technically the answer is no, but I think practically speaking, it would be unusual for someone to use this driver and not have a UART bus. Do you think I should require the UART bus for now? If you're not using the UART, it's very easy to emulate using basic drivers. Edit: Decided to make it required for this driver. |
2eeef0d
to
209abb7
Compare
Added __ASSERT Validation of UART Parameters to Init function |
209abb7
to
adbeaf3
Compare
|
Also, should this be retagged to v4.3.0 milestone, or is v4.2.0 still open? |
Yes, unfortunately this missed the deadline for the 4.2 release as feature freeze was last Friday. Getting a brand new 2000-line PR reviewed in just 10 short days right as everyone was wrapping up their own contributions was probably a bit ambitious unfortunately. Hope you understand! |
Just to check - until v4.2 is released (7/18), merging is blocked, correct? |
Correct. Everything goes into |
Since 4.2 has released, can the reviewers take a look at this when they get a moment? We're planning a follow-up to this merge with another commit containing a device sample *(in the near future) |
} | ||
|
||
/* Sensor APIs */ | ||
static const struct sensor_driver_api mtch9010_api_funcs = { |
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.
Use DEVICE_API
@@ -0,0 +1,16 @@ | |||
&uart1 { |
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.
overlay files are missing license/copyright headers
status = "okay"; | ||
compatible = "microchip,mtch9010"; | ||
|
||
// Device Configuration |
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.
no c99 comments please
adbeaf3
to
15420a7
Compare
15420a7
to
0906ad8
Compare
Added support for MTCH9010 and applied edits from reviewers. Signed-off-by: Robert Perkel <[email protected]>
0906ad8
to
6b8e278
Compare
|
Added new driver for MTCH9010 liquid leak detector along with test patterns.