-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpyb.py
1062 lines (854 loc) · 20.8 KB
/
pyb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
def delay(ms):
"""
Delay for the given number of milliseconds.
"""
pass
def udelay(us):
"""
Delay for the given number of microseconds.
"""
pass
def millis():
"""
Returns the number of milliseconds since the board was last reset.
"""
pass
def micros():
"""
Returns the number of microseconds since the board was last reset.
"""
pass
def elapsed_millis(start):
"""
Returns the number of milliseconds which have elapsed since ``start``.
"""
pass
def elapsed_micros(start):
"""
Returns the number of microseconds which have elapsed since ``start``.
"""
pass
def hard_reset():
"""
Resets the pyboard in a manner similar to pushing the external RESET
button.
"""
def bootloader():
"""
Activate the bootloader without BOOT\* pins.
"""
pass
def disable_irq():
"""
Disable interrupt requests.
"""
pass
def enable_irq(state=True):
"""
Enable interrupt requests.
"""
pass
def freq(sysclk, hclk, pclk1, pclk2):
"""
If given no arguments, returns a tuple of clock frequencies.
"""
pass
def wfi():
"""
Wait for an internal or external interrupt.
"""
pass
def stop():
"""
Put the pyboard in a "sleeping" state.
"""
def standby():
"""
Put the pyboard into a "deep sleep" state.
"""
pass
def info(dump_alloc_table):
"""
Print out lots of information about the board.
"""
pass
def main(filename):
"""
Set the filename of the main script to run after boot.py is finished.
"""
pass
def mount(device, mountpoint, *, readonly=False, mkfs=False):
"""
Mount a block device and make it available as part of the filesystem.
"""
pass
def repl_uart(uart):
"""
Get or set the UART object where the REPL is repeated on.
"""
pass
def rng():
"""
Return a 30-bit hardware generated random number.
"""
pass
def sync():
"""
Sync all file systems.
"""
pass
def unique_id():
"""
Returns a string of 12 bytes (96 bits), which is the unique ID of the MCU.
"""
pass
def usb_mode(modestr, vid=0xf055, pid=0x9801, hid=None):
"""
If called with no arguments, return the current USB mode as a string.
If called with modestr provided, attempts to set USB mode.
"""
pass
class Accel:
def filtered_xyz(self):
"""
Get a 3-tuple of filtered x, y and z values.
"""
pass
def tilt(self):
"""
Get the tilt register.
"""
pass
def x(self):
"""
Get the x-axis value.
"""
pass
def y(self):
"""
Get the y-axis value.
"""
pass
def z(self):
"""
Get the z-axis value.
"""
pass
def write(self, register, value):
pass
def read(self, register):
pass
class ADC:
def __init__(self, pin):
"""
Create an ADC object associated with the given pin.
This allows you to then read analog values on that pin.
"""
pass
def read(self):
"""
Read the value on the analog pin and return it. The returned value
will be between 0 and 4095.
"""
pass
def read_timed(buf, timer):
"""
Read analog values into ``buf`` at a rate set by the ``timer`` object.
"""
pass
class CAN:
NORMAL = "NORMAL"
LOOPBACK = "LOOPBACK"
SILENT = "SILENT"
SILENT_LOOPBACK = "SILENT_LOOPBACK"
LIST16 = "LIST16"
MASK16 = "MASK16"
LIST32 = "LIST32"
MASK32 = "MASK32"
def __init__(self, bus, mode=None, extframe=False, prescaler=100, *, sjw=1, bs1=6, bs2=8):
"""
Construct a CAN object on the given bus.
"""
pass
@classmethod
def initfilterbanks(cls, nr):
"""
Reset and disable all filter banks and assign how many banks should be available for CAN(1).
"""
pass
def init(self, mode, extframe=False, prescaler=100, *, sjw=1, bs1=6, bs2=8):
"""
Initialise the CAN bus with the given parameters
"""
pass
def deinit(self):
"""
Turn off the CAN bus.
"""
pass
def setfilter(self, bank, mode, fifo, params, *, rtr):
"""
Configure a filter bank
"""
pass
def clearfilter(bank):
"""
Clear and disables a filter bank.
"""
pass
def any(fifo):
"""
Return True if any message waiting on the FIFO, else False.
"""
pass
def recv(fifo, *, timeout=5000):
"""
Receive data on the bus.
"""
pass
def send(data, id, *, timeout=0, rtr=False):
"""
Send a message on the bus.
"""
pass
def rxcallback(fifo, fun):
"""
Register a function to be called when a message is accepted into a empty fifo:
"""
pass
class DAC:
NORMAL = "NORMAL"
CIRCULAR = "CIRCULAR"
def __init__(self, port, bits=8):
"""
Construct a new DAC object.
"""
pass
def init(self, bits=8):
"""
Reinitialise the DAC. ``bits`` can be 8 or 12.
"""
pass
def deinit():
"""
De - initialise the DAC making its pin available for other uses.
"""
def noise(self, freq):
"""
Generate a pseudo-random noise signal.
"""
pass
def triangle(self, freq):
"""
Generate a triangle wave.
"""
pass
def write(self, value):
"""
Direct access to the DAC output.
"""
pass
def write_timed(self, data, freq, *, mode=NORMAL):
"""
Initiates a burst of RAM to DAC using a DMA transfer.
"""
pass
class ExtInt:
IRQ_FALLING = "IRQ_FALLING"
IRQ_RISING = "IRQ_RISING"
IRQ_RISING_FALLING = "IRQ_RISING_FALLING"
def __init__(self, pin, mode, pull, callback):
"""
Create an ExtInt object
"""
pass
@classmethod
def regs(cls):
"""
Dump the values of the EXTI registers.
"""
def disable(self, ):
"""
Disable the interrupt associated with the ExtInt object.
This could be useful for debouncing.
"""
pass
def enable(self, ):
"""
Enable a disabled interrupt.
"""
pass
def line(self, ):
"""
Return the line number that the pin is mapped to.
"""
pass
def swint(self, ):
"""
Trigger the callback from software.
"""
pass
class I2C:
MASTER = "MASTER"
SLAVE = "SLAVE"
def __init__(self, bus):
"""
Construct an I2C object on the given bus.
"""
pass
def deinit(self):
"""
Turn off the I2C bus.
"""
pass
def init(self, mode, *, addr=0x12, baudrate=400000, gencall=False):
"""
Initialise the I2C bus with the given parameters.
"""
pass
def is_ready(self, addr):
"""
Check if an I2C device responds to the given address. Only valid when in master mode.
"""
pass
def mem_read(self, data, addr, memaddr, *, timeout=5000, addr_size=8):
"""
Read from the memory of an I2C device.
"""
pass
def mem_write(self, data, addr, memaddr, *, timeout=5000, addr_size=8):
"""
Write to the memory of an I2C device.
"""
pass
def recv(self, recv, addr=0x00, *, timeout=5000):
"""
Receive data on the bus.
"""
pass
def send(self, send, addr=0x00, *, timeout=5000):
"""
Send data on the bus.
"""
pass
def scan(self):
"""
Scan all I2C addresses from 0x01 to 0x7f and return a list of those that respond.
"""
pass
class LCD:
def __init__(self, skin_position):
"""
Construct an LCD object in the given skin position. ``skin_position`` can be 'X' or 'Y', and
should match the position where the LCD pyskin is plugged in.
"""
pass
def command(self, instr_data, buf):
"""
Send an arbitrary command to the LCD. Pass 0 for ``instr_data`` to send an
instruction, otherwise pass 1 to send data. ``buf`` is a buffer with the
instructions/data to send.
"""
def contrast(self, value):
"""
Set the contrast of the LCD. Valid values are between 0 and 47.
"""
pass
def fill(self, colour):
"""
Fill the screen with the given colour (0 or 1 for white or black).
"""
pass
def get(self, x, y):
"""
Get the pixel at the position ``(x, y)``. Returns 0 or 1.
"""
pass
def light(self, value):
"""
Turn the backlight on/off. True or 1 turns it on, False or 0 turns it off.
"""
pass
def pixel(self, x, y, colour):
"""
Set the pixel at ``(x, y)`` to the given colour (0 or 1).
"""
pass
def show(self, ):
"""
Show the hidden buffer on the screen.
"""
pass
def text(self, str, x, y, colour):
"""
Draw the given text to the position ``(x, y)`` using the given colour (0 or 1).
"""
pass
def write(self, str):
"""
Write the string ``str`` to the screen. It will appear immediately.
"""
pass
class LED:
def __init__(self, id):
"""
Create an LED object associated with the given LED
"""
pass
def intensity(self, value):
"""
Get or set the LED intensity. Intensity ranges between 0 (off) and 255 (full on).
"""
def off(self, ):
"""
Turn the LED off.
"""
pass
def on(self, ):
"""
Turn the LED on, to maximum intensity.
"""
pass
def toggle(self, ):
"""
Toggle the LED between on (maximum intensity) and off.
"""
pass
class Pin:
AF_OD = "AF_OD"
AF_PP = "AF_PP"
ANALOG = "ANALOG"
IN = "IN"
OUT_OD = "OUT_OD"
OUT_PP = "OUT_PP"
PULL_DOWN = "PULL_DOWN"
PULL_NONE = "PULL_NONE"
PULL_UP = "PULL_UP"
def __init__(self, id):
"""
Create a new Pin object associated with the id.
"""
pass
@classmethod
def debug(cls, state):
"""
Get or set the debugging state (``True`` or ``False`` for on or off).
"""
pass
@classmethod
def dict(cls, dict):
"""
Get or set the pin mapper dictionary.
"""
pass
@classmethod
def mapper(cls, fun):
"""
Get or set the pin mapper function.
"""
pass
def init(self, mode, pull=PULL_NONE, af=-1):
"""
Initialise the pin:
"""
pass
def value(self, value):
"""
Get or set the digital logic level of the pin.
"""
pass
def __str__(self):
"""
Return a string describing the pin object.
"""
pass
def af(self):
"""
Returns the currently configured alternate-function of the pin.
"""
pass
def af_list(cls, ):
"""
Returns an array of alternate functions available for this pin.
"""
pass
def gpio(self):
"""
Returns the base address of the GPIO block associated with this pin.
"""
pass
def mode(self):
"""
Returns the currently configured mode of the pin.
"""
pass
def name(self):
"""
Get the pin name.
"""
pass
def names(self):
"""
Returns the cpu and board names for this pin.
"""
pass
def pin(self):
"""
Get the pin number.
"""
pass
def port(self):
"""
Get the pin port.
"""
pass
def pull(self):
"""
Returns the currently configured pull of the pin.
"""
pass
class PinAF:
def __str__(self):
"""
Return a string describing the alternate function.
"""
pass
def index(self):
"""
Return the alternate function index.
"""
pass
def name(self):
"""
Return the name of the alternate function.
"""
pass
def reg(self):
"""
Return the base register associated with the peripheral assigned to this
alternate function.
"""
pass
class RTC:
def __init__(self):
"""
Create an RTC object.
"""
pass
def datetime(self, datetimetuple):
"""
Get or set the date and time of the RTC.
"""
pass
def wakeup(self, timeout, callback=None):
"""
Set the RTC wakeup timer to trigger repeatedly at every ``timeout``
milliseconds.
"""
pass
def info(self):
"""
Get information about the startup time and reset source.
"""
pass
def calibration(self, cal):
"""
Get or set RTC calibration.
"""
pass
class Servo:
def __init__(self, id):
"""
Create a servo object. ``id`` is 1-4, and corresponds to pins X1 through X4.
"""
pass
def angle(self, angle, time=0):
"""
If no arguments are given, this function returns the current angle.
"""
pass
def speed(self, speed, time=0):
"""
If no arguments are given, this function returns the current speed.
"""
pass
def pulse_width(self, value):
"""
If no arguments are given, this function returns the current raw pulse-width
value.
"""
pass
def calibration(self, pulse_min, pulse_max, pulse_centre, pulse_angle_90, pulse_speed_100):
"""
If no arguments are given, this function returns the current calibration
data, as a 5-tuple.
"""
pass
class SPI:
MASTER = "MASTER"
SLAVE = "SLAVE"
LSB = "LSB"
MSB = "MSB"
def __init__(self, bus):
"""
Construct an SPI object on the given bus.
"""
pass
def deinit(self):
"""
Turn off the SPI bus.
"""
pass
def init(self, mode, baudrate=328125, *, prescaler, polarity=1, phase=0, bits=8, firstbit=MSB, ti=False, crc=None):
"""
Initialise the SPI bus with the given parameters:
"""
pass
def recv(self, recv, *, timeout=5000):
"""
Receive data on the bus:
"""
pass
def send(self, send, *, timeout=5000):
"""
Send data on the bus:
"""
pass
def send_recv(self, send, recv=None, *, timeout=5000):
"""
Send and receive data on the bus at the same time:
"""
pass
class Switch:
def __init__(self):
"""
Create and return a switch object.
"""
pass
def __call__():
"""
Call switch object directly to get its state: True if pressed down, False otherwise.
"""
pass
def callback(self, fun):
"""
Register the given function to be called when the switch is pressed down.
"""
pass
class Timer:
PWM = "PWM"
def __init__(self, id, **kwargs):
"""
Construct a new timer object of the given id.
"""
pass
def init(self, *, freq, prescaler, period):
"""
Initialise the timer.
"""
pass
def deinit(self):
"""
Deinitialises the timer.
"""
pass
def callback(self, fun):
"""
Set the function to be called when the timer triggers.
"""
pass
def channel(self, channel, mode, **kwargs):
"""
If only a channel number is passed, then a previously initialized channel
object is returned (or ``None`` if there is no previous channel).
"""
return TimerChannel()
def counter(self, value):
"""
Get or set the timer counter.
"""
def freq(self, value):
"""
Get or set the frequency for the timer (changes prescaler and period if set).
"""
pass
def period(self, value):
"""
Get or set the period of the timer.
"""
pass
def prescaler(self, value):
"""
Get or set the prescaler for the timer.
"""
pass
def source_freq(self):
"""
Get the frequency of the source of the timer.
"""
pass
class TimerChannel:
def callback(self, fun):
"""
Set the function to be called when the timer channel triggers.
"""
pass
def capture(self, value):
"""
Get or set the capture value associated with a channel.
"""
pass
def compare(self, value):
"""
Get or set the compare value associated with a channel.
"""
pass
def pulse_width(self, value):
"""
Get or set the pulse width value associated with a channel.
"""
def pulse_width_percent(self, value):
"""
Get or set the pulse width percentage associated with a channel.
"""
pass
class UART:
RTS = "RTS"
CTS = "CTS"
def __init__(self, bus):
"""
Construct a UART object on the given bus.
"""
pass
def init(self, baudrate, bits=8, parity=None, stop=1, *, timeout=1000, flow=None, timeout_char=0, read_buf_len=64):
"""
Initialise the UART bus with the given parameters:
"""
pass
def deinit(self):
"""
Turn off the UART bus.
"""
pass
def any(self):
"""
Return ``True`` if any characters waiting, else ``False``.
"""
pass
def writechar(self, char):
"""
Write a single character on the bus.
"""
pass
def read(self, nbytes):
"""
Read characters.
"""
pass
def readchar(self):
"""
Receive a single character on the bus.
"""
pass
def readinto(self, buf, nbytes):
"""
Read bytes into the ``buf``.
"""
pass
def readline(self):
"""
Read a line, ending in a newline character.
"""
pass
def write(self, buf):
"""
Write the buffer of bytes to the bus.
"""
pass
def writechar(char):
"""
Write a single character on the bus. char is an integer to write.
Return value: None. See note below if CTS flow control is used.
"""
pass
def sendbreak(self):
"""
Send a break condition on the bus.
"""
pass
class USB_HID:
"""
Create a new USB_HID object.
"""
def recv(data, *, timeout=5000):
"""
Receive data on the bus.
"""
pass
def send(data):
"""
Send data over the USB HID interface:
"""
pass
class USB_VCP:
def __init__(self):
"""
Create a new USB_VCP object.
"""
pass
def setinterrupt(self, chr):
"""
Set the character which interrupts running Python code.
"""