tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/pca9685/registers.go (about)

     1  package pca9685
     2  
     3  // Software reset addresses for generic i2c implementation
     4  // and PCA specific SWRST. See section 7.6
     5  const (
     6  	I2CSWRSTADR      = 0x0
     7  	PCA9685SWRSTBYTE = 0b0000_0110 // 0x06
     8  )
     9  
    10  // Registries with nomenclature as seen in manual
    11  const (
    12  	SUBADR1 uint8 = 0x2
    13  	SUBADR2 uint8 = 0x3
    14  	SUBADR3 uint8 = 0x4
    15  
    16  	MODE1      uint8 = 0x0
    17  	MODE2      uint8 = 0x1
    18  	ALLCALLADR uint8 = 0x05
    19  
    20  	SWRESET uint8 = 0b0000_0011
    21  
    22  	// Start of LED registries. corresponds to LED0_ON_L register.
    23  	// Use LED function to get registries of a specific PWM channel register.
    24  	LEDSTART = 0x06
    25  )
    26  
    27  // MODE1
    28  const (
    29  	RESET             byte = 0b1000_0000
    30  	EXTCLK            byte = 0b0100_0000
    31  	AI                byte = 0b0010_0000
    32  	SLEEP             byte = 0b0001_0000
    33  	defaultMODE1Value byte = 0b0001_0001
    34  )
    35  
    36  // MODE2
    37  const (
    38  	OUTDRV = 1 << 2
    39  	INVRT  = 1 << 4
    40  )
    41  
    42  // LED channels from 0-15. Returns 4 registries associated with
    43  // the channel PWM signal. Channel 250 (0xFA) gives ALL_LED registers.
    44  // The L suffix represents the 8 LSB of 12 bit timing, the H suffix represents
    45  // the 4 MSB of the timing. This way you have 0-4095 timing options. ON or OFF
    46  // will be a number between these two or will be simply ON or OFF (fifth bit of H registry).
    47  //
    48  // The SetPWM implementation in this library does not do phase-shifting so OFF will always
    49  // happen at time stamp 0. ON will solely decide duty cycle.
    50  func LED(ch uint8) (ONL, ONH, OFFL, OFFH uint8) {
    51  	switch {
    52  	case ch == ALLLED:
    53  		return ALLLED, ALLLED + 1, ALLLED + 2, ALLLED + 3
    54  
    55  	case ch > 15:
    56  		panic("PWM channel out of range [0-15]")
    57  	default:
    58  	}
    59  	// 4 registries per channel. Starts at 6
    60  	onLReg := LEDSTART + 4*ch
    61  	return onLReg, onLReg + 1, onLReg + 2, onLReg + 3
    62  }
    63  
    64  const (
    65  	// ALLLED is channel that selects registries to control all leds. Use with function LED
    66  	ALLLED = 0xfa
    67  	// PRESCALE Prescaling byte
    68  	PRESCALE byte = 0xFE
    69  )