MCPcopy
hub / github.com/tinygo-org/tinygo / Channel

Method Channel

src/machine/machine_atmega1280.go:484–553  ·  view source on GitHub ↗

Channel returns a PWM channel for the given pin.

(pin Pin)

Source from the content-addressed store, hash-verified

482
483// Channel returns a PWM channel for the given pin.
484func (pwm PWM) Channel(pin Pin) (uint8, error) {
485 pin.Configure(PinConfig{Mode: PinOutput})
486 pin.Low()
487 switch pwm.num {
488 case 0:
489 switch pin {
490 case PB7: // channel A
491 avr.TCCR0A.SetBits(avr.TCCR0A_COM0A1)
492 return 0, nil
493 case PG5: // channel B
494 avr.TCCR0A.SetBits(avr.TCCR0A_COM0B1)
495 return 1, nil
496 }
497 case 1:
498 switch pin {
499 case PB5: // channel A
500 avr.TCCR1A.SetBits(avr.TCCR1A_COM1A1)
501 return 0, nil
502 case PB6: // channel B
503 avr.TCCR1A.SetBits(avr.TCCR1A_COM1B1)
504 return 1, nil
505 }
506 case 2:
507 switch pin {
508 case PB4: // channel A
509 avr.TCCR2A.SetBits(avr.TCCR2A_COM2A1)
510 return 0, nil
511 case PH6: // channel B
512 avr.TCCR2A.SetBits(avr.TCCR2A_COM2B1)
513 return 1, nil
514 }
515 case 3:
516 switch pin {
517 case PE3: // channel A
518 avr.TCCR3A.SetBits(avr.TCCR3A_COM3A1)
519 return 0, nil
520 case PE4: //channel B
521 avr.TCCR3A.SetBits(avr.TCCR3A_COM3B1)
522 return 1, nil
523 case PE5: //channel C
524 avr.TCCR3A.SetBits(avr.TCCR3A_COM3C1)
525 return 2, nil
526 }
527 case 4:
528 switch pin {
529 case PH3: // channel A
530 avr.TCCR4A.SetBits(avr.TCCR4A_COM4A1)
531 return 0, nil
532 case PH4: //channel B
533 avr.TCCR4A.SetBits(avr.TCCR4A_COM4B1)
534 return 1, nil
535 case PH5: //channel C
536 avr.TCCR4A.SetBits(avr.TCCR4A_COM4C1)
537 return 2, nil
538 }
539 case 5:
540 switch pin {
541 case PL3: // channel A

Callers

nothing calls this directly

Calls 3

LowMethod · 0.80
ConfigureMethod · 0.65
SetBitsMethod · 0.45

Tested by

no test coverage detected