mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-14 20:03:40 +00:00
rewrite enum implementations
This commit is contained in:
+14
-21
@@ -68,18 +68,16 @@ const (
|
|||||||
type Drive uint8
|
type Drive uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
_ Drive = iota
|
Drive100mA Drive = iota
|
||||||
Drive12_5mA
|
|
||||||
Drive25mA
|
|
||||||
Drive50mA
|
Drive50mA
|
||||||
Drive100mA
|
Drive25mA
|
||||||
|
Drive12_5mA
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
StartMode Enable
|
ProxGain ProxGain
|
||||||
LEDDrive Drive
|
ALSGain ALSGain
|
||||||
// ALSGain ALSGain
|
LEDDrive Drive
|
||||||
// ProximityGain ProxGain
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dev) Init(cfg Config) error {
|
func (d *Dev) Init(cfg Config) error {
|
||||||
@@ -92,16 +90,13 @@ func (d *Dev) Init(cfg Config) error {
|
|||||||
d.txWrite8(regPPULSE, 0x04)
|
d.txWrite8(regPPULSE, 0x04)
|
||||||
d.txWrite8(regWTIME, 0xee) // set default wait time.
|
d.txWrite8(regWTIME, 0xee) // set default wait time.
|
||||||
d.txWrite8(regPTIME, 0xff) // set default pulse count.
|
d.txWrite8(regPTIME, 0xff) // set default pulse count.
|
||||||
if d.txErr() != nil {
|
|
||||||
return d.txErr()
|
var ctlval uint8 = 0b10 << 4 // Use Channel 1 diode.
|
||||||
}
|
ctlval |= uint8(cfg.LEDDrive&0b11) << 6
|
||||||
if cfg.LEDDrive != 0 {
|
ctlval |= uint8(cfg.ProxGain&0b11) << 2
|
||||||
err := d.SetLEDDrive(cfg.LEDDrive)
|
ctlval |= uint8(cfg.ALSGain & 0b11)
|
||||||
if err != nil {
|
d.txWrite8(regCONTROL, ctlval)
|
||||||
return err
|
return d.txErr()
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dev) Status() (Status, error) {
|
func (d *Dev) Status() (Status, error) {
|
||||||
@@ -125,7 +120,6 @@ func (d *Dev) enableLightSensor(withInterrupts bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dev) setAmbientLightGain() {
|
func (d *Dev) setAmbientLightGain() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Dev) EnableProximity() error {
|
func (d *Dev) EnableProximity() error {
|
||||||
@@ -158,7 +152,7 @@ func (d *Dev) setProxIntHighThresh(hiThresh uint16) error {
|
|||||||
func (d *Dev) LEDDrive() (Drive, error) {
|
func (d *Dev) LEDDrive() (Drive, error) {
|
||||||
d.txNew()
|
d.txNew()
|
||||||
val := (d.txRead8(regCONTROL) >> 6) & 0b11
|
val := (d.txRead8(regCONTROL) >> 6) & 0b11
|
||||||
return 3 - Drive(val), d.txErr()
|
return Drive(val), d.txErr()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLEDDrive drive strength for proximity and ALS
|
// SetLEDDrive drive strength for proximity and ALS
|
||||||
@@ -172,7 +166,6 @@ func (d *Dev) SetLEDDrive(drive Drive) error {
|
|||||||
if drive > 3 {
|
if drive > 3 {
|
||||||
return errInvalidParam
|
return errInvalidParam
|
||||||
}
|
}
|
||||||
drive = 3 - drive
|
|
||||||
current, err := d.LEDDrive()
|
current, err := d.LEDDrive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user