Files
tinygo/src/machine/machine_nrf52840_simulator.go
T
Ayke van Laethem f845b469b1 machine: make I2C usable in the simulator
This fixes/improves a few issues with I2C support:

  * Validate I2C pins, so only pins that are supported by the hardware
    can be used (similar to how it's done with PWM).
  * Add address to Tx API (without it, the simulator can't really
    simulate I2C).
  * Add frequency when configuring. Not currently used, but might be
    useful in the future and adding it now avoids possibly breaking
    changes.

This is a breaking change, but since the simulator doesn't support I2C
yet that seems fine to me. (It does in my local changes, but those need
to be cleaned up before I can push them).
2025-07-11 09:25:48 +02:00

64 lines
1.4 KiB
Go

//go:build !baremetal && (bluemicro840 || circuitplay_bluefruit || clue_alpha || feather_nrf52840_sense || feather_nrf52840 || itsybitsy_nrf52840 || mdbt50qrx || nano_33_ble || nicenano || nrf52840_mdk || particle_3rd_gen || pca10056 || pca10059 || rak4631 || reelboard || xiao_ble)
// Simulator support for nrf52840 based boards.
package machine
// Channel values below are nil, so that they get filled in on the first use.
// This is the same as what happens on baremetal.
var PWM0 = &timerType{
instance: 0,
frequency: 16e6,
bits: 15,
prescalers: []int{1, 2, 4, 8, 16, 32, 64, 128},
channelPins: [][]Pin{
nil, // channel 0
nil, // channel 1
nil, // channel 2
nil, // channel 3
},
}
var PWM1 = &timerType{
instance: 1,
frequency: 16e6,
bits: 15,
prescalers: []int{1, 2, 4, 8, 16, 32, 64, 128},
channelPins: [][]Pin{
nil, // channel 0
nil, // channel 1
nil, // channel 2
nil, // channel 3
},
}
var PWM2 = &timerType{
instance: 2,
frequency: 16e6,
bits: 15,
prescalers: []int{1, 2, 4, 8, 16, 32, 64, 128},
channelPins: [][]Pin{
nil, // channel 0
nil, // channel 1
nil, // channel 2
nil, // channel 3
},
}
var PWM3 = &timerType{
instance: 3,
frequency: 16e6,
bits: 15,
prescalers: []int{1, 2, 4, 8, 16, 32, 64, 128},
channelPins: [][]Pin{
nil, // channel 0
nil, // channel 1
nil, // channel 2
nil, // channel 3
},
}
var I2C0 = &I2C{Bus: 0}
var I2C1 = &I2C{Bus: 1}