adc

package
v0.0.0-...-168ccc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2021 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package adc provides interface to STM32 Analog to Digital Converter peripheral. Additionaly it provides two drivers for easier use of ADC.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CircDriver

type CircDriver struct {
	// contains filtered or unexported fields
}

func NewCircDriver

func NewCircDriver(p *Periph, ch *dma.Channel, chunkLen int) *CircDriver

NewCircDriver returns new circural driver using p and ch with internal buffers of total size 4*chunkLen bytes.

func (*CircDriver) Bytes

func (d *CircDriver) Bytes(bh int32) []byte

func (*CircDriver) DMA

func (d *CircDriver) DMA() *dma.Channel

func (*CircDriver) DMAISR

func (d *CircDriver) DMAISR()

func (*CircDriver) Enable

func (d *CircDriver) Enable(calibrate bool)

func (*CircDriver) Err

func (d *CircDriver) Err() error

func (*CircDriver) HandleChan

func (d *CircDriver) HandleChan() <-chan int32

HandleChan returns the channel that can be used to obtain buffer handles.

func (*CircDriver) ISR

func (d *CircDriver) ISR()

func (*CircDriver) P

func (d *CircDriver) P() *Periph

func (*CircDriver) Start

func (d *CircDriver) Start(wordSize, byteOffset uintptr)

func (*CircDriver) Stop

func (d *CircDriver) Stop()

func (*CircDriver) Words16

func (d *CircDriver) Words16(bh int32) []uint16

type Driver

type Driver struct {
	P   *Periph
	DMA *dma.Channel
	// contains filtered or unexported fields
}

func NewDriver

func NewDriver(p *Periph, ch *dma.Channel) *Driver

NewDriver provides convenient way to create heap allocated Driver.

func (*Driver) DMAISR

func (d *Driver) DMAISR()

func (*Driver) Enable

func (d *Driver) Enable(calibrate bool)

Enable enables ADC.

func (*Driver) ISR

func (d *Driver) ISR()

func (*Driver) Read

func (d *Driver) Read(buf []byte) (int, error)

Read uses DMA in one shot mode so can not read more than 65535 samples.

func (*Driver) Read16

func (d *Driver) Read16(buf []uint16) (int, error)

Read16 uses DMA in one shot mode so can not read more than 65535 samples.

func (*Driver) SetReadMSB

func (d *Driver) SetReadMSB(rdmsb bool)

SetReadMSB sets most significant byte of 16-bit ADC data register to be read by Read and ReadByte methods.

type DriverError

type DriverError byte
const (
	ErrDrvOverrun DriverError = 1
)

func (DriverError) Error

func (e DriverError) Error() string

type Error

type Error uint16
const ErrAll Error = errAll

func (Error) Error

func (e Error) Error() string

type Event

type Event uint16
const EvAll Event = evAll

type Periph

type Periph struct {
	// contains filtered or unexported fields
}

func (*Periph) Bus

func (p *Periph) Bus() system.Bus

Bus returns a bus to which p is connected to.

func (*Periph) Calibrate

func (p *Periph) Calibrate()

Calibrate calibrates p.

func (*Periph) Clear

func (p *Periph) Clear(ev Event, err Error)

func (*Periph) Disable

func (p *Periph) Disable()

Disable disables p. Use Enabled to check that p is effectively disabled.

func (*Periph) DisableClock

func (p *Periph) DisableClock()

DisableClock disables clock for p. In some MCUs clock cannot be disabled for only one ADC, then DisableClock can affects a pair of peripherals (eg. ADC1.DisableClock() can affect ADC1 and ADC2 simultaneously).

func (*Periph) DisableDMA

func (p *Periph) DisableDMA()

func (*Periph) DisableIRQ

func (p *Periph) DisableIRQ(ev Event, err Error)

func (*Periph) Enable

func (p *Periph) Enable()

Enable enables p.

func (*Periph) EnableClock

func (p *Periph) EnableClock(lp bool)

EnableClock enables clock for p. Lp determines whether the clock remains on in low power (sleep) mode. In some MCUs clock cannot be enabled for only one ADC, then EnableClock can affects a pair of peripherals (eg. ADC1.EnableClock() can affect ADC1 and ADC2 simultaneously).

func (*Periph) EnableDMA

func (p *Periph) EnableDMA(circural bool)

func (*Periph) EnableIRQ

func (p *Periph) EnableIRQ(ev Event, err Error)

func (*Periph) Enabled

func (p *Periph) Enabled() bool

Enabled reports whether p is enabled.

func (*Periph) Raw

func (p *Periph) Raw() *adc.ADC_Periph

func (*Periph) SetAlignLeft

func (p *Periph) SetAlignLeft(alignLeft bool)

func (*Periph) SetSamplTime

func (p *Periph) SetSamplTime(ch int, st SamplTime)

SetSamplTime sets sampling time for channel ch.

func (*Periph) SetSequence

func (p *Periph) SetSequence(ch ...int)

SetSequence sets regular sequence of channels.

func (*Periph) SetTrigEdge

func (p *Periph) SetTrigEdge(edge TrigEdge)

func (*Periph) SetTrigSrc

func (p *Periph) SetTrigSrc(src TrigSrc)

SetTrigSrc selects source of external trigger.

func (*Periph) Start

func (p *Periph) Start()

func (*Periph) Status

func (p *Periph) Status() (Event, Error)

func (*Periph) Stop

func (p *Periph) Stop()

type SamplTime

type SamplTime int8

func MaxSamplTime

func MaxSamplTime(hc int) SamplTime

MaxSamplTime returns the largest possible value of sampling time that takes no more than hc half clock cycles. If ht is too small MaxSamplTime returns negative value.

func (SamplTime) HalfCycles

func (st SamplTime) HalfCycles() int

HalfCycles returns number of half clock cycles that st corresponds to.

type TrigEdge

type TrigEdge byte
const (
	EdgeNone   TrigEdge = 0
	EdgeRising TrigEdge = 1
)

type TrigSrc

type TrigSrc byte

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL