-
Notifications
You must be signed in to change notification settings - Fork 205
Add support for bme68x sensor #751
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: dev
Are you sure you want to change the base?
Conversation
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.
lots of good stuff and also some stuff to improve. hope this helps :)
// REG_MEM_PAGE is the MEM_PAGE address | ||
REG_MEM_PAGE uint8 = 0xF3 | ||
// MEM_PAGE_MSK is mask for SPI memory page | ||
MEM_PAGE_MSK uint8 = 0x10 | ||
// SPI_RD_MSK is the mask for reading a register in SPI | ||
SPI_RD_MSK uint8 = 0x80 | ||
// SPI_WR_MSK is the mask for writing a register in SPI | ||
SPI_WR_MSK uint8 = 0x7F | ||
// MEM_PAGE0 is the SPI memory page 0 | ||
MEM_PAGE0 uint8 = 0x10 | ||
// MEM_PAGE1 is the SPI memory page 1 | ||
MEM_PAGE1 uint8 = 0x00 |
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.
maybe unexport
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.
This is specific to SPI but it defines the register address of SPI interface as well the other registers which are all exported. I don't think it's such a bit problem having them exported.
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.
If the user already has access to the Read/Write layer, they don't really need them. They might need the registers but not this...
func (s *spi) read(reg uint8, data []byte) error { | ||
reg |= SPI_RD_MSK | ||
|
||
return s.bus.Tx([]byte{reg}, 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.
beware heap alloc here.
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.
how to avoid heap in this case?
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.
Key is always pass in the spi's in-struct array to Tx. All you gotta do is fill it with the correct data.
s.bus.wbuf[0] = reg | SPI_RD_MSK
n := copy(s.bus.wbuf[:], data)
return s.bus.Tx(s.bus.wbuf[:n], s.bus.rbuf[:n])
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.
Also, your driver is technically incorrect, you should always pass in equal length buffers to Tx, or one of them should be nil
data[0] &^= MEM_PAGE_MSK | ||
data[0] |= (memoryPage & MEM_PAGE_MSK) | ||
|
||
return s.bus.Tx([]byte{REG_MEM_PAGE | SPI_WR_MSK}, []byte{data[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.
heap
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.
how to avoid heap in this case?
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.
Same rules as above. use in-struct arrays. please refer to https://deploy-preview-451--tinygo.netlify.app/docs/guides/driver-design/
If the path to avoiding heap allocations is not clear please leave a comment here with what is missing or could be improved: tinygo-org/tinygo-site#451
This PR adds support for BME68X (BME680/BME688) a low power gas, pressure, temperature & humidity sensor.
It includes the support for Sleep and Forced modes as well I2C and SPI interfaces. It introduces the
Options Pattern
to make the initialization ofbme68x
package more flexible.Simple example: