Skip to content

Commit 838b6c5

Browse files
committed
Did ps2io, pulseio, random
1 parent 09530e5 commit 838b6c5

File tree

7 files changed

+278
-278
lines changed

7 files changed

+278
-278
lines changed

shared-bindings/ps2io/Ps2.c

Lines changed: 68 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -36,38 +36,39 @@
3636
#include "shared-bindings/util.h"
3737
#include "supervisor/shared/translate.h"
3838

39-
//| .. currentmodule:: ps2io
39+
//| class Ps2:
40+
//| """.. currentmodule:: ps2io
4041
//|
41-
//| :class:`Ps2` -- Communicate with a PS/2 keyboard or mouse
42-
//| =========================================================
42+
//| :class:`Ps2` -- Communicate with a PS/2 keyboard or mouse
43+
//| =========================================================
4344
//|
44-
//| Ps2 implements the PS/2 keyboard/mouse serial protocol, used in
45-
//| legacy devices. It is similar to UART but there are only two
46-
//| lines (Data and Clock). PS/2 devices are 5V, so bidirectional
47-
//| level converters must be used to connect the I/O lines to pins
48-
//| of 3.3V boards.
45+
//| Ps2 implements the PS/2 keyboard/mouse serial protocol, used in
46+
//| legacy devices. It is similar to UART but there are only two
47+
//| lines (Data and Clock). PS/2 devices are 5V, so bidirectional
48+
//| level converters must be used to connect the I/O lines to pins
49+
//| of 3.3V boards."""
4950
//|
50-
//| .. class:: Ps2(data_pin, clock_pin)
51+
//| def __init__(self, data_pin: microcontroller.Pin, clock_pin: microcontroller.Pin):
52+
//| """Create a Ps2 object associated with the given pins.
5153
//|
52-
//| Create a Ps2 object associated with the given pins.
54+
//| :param ~microcontroller.Pin data_pin: Pin tied to data wire.
55+
//| :param ~microcontroller.Pin clock_pin: Pin tied to clock wire.
56+
//| This pin must support interrupts.
5357
//|
54-
//| :param ~microcontroller.Pin data_pin: Pin tied to data wire.
55-
//| :param ~microcontroller.Pin clock_pin: Pin tied to clock wire.
56-
//| This pin must support interrupts.
58+
//| Read one byte from PS/2 keyboard and turn on Scroll Lock LED::
5759
//|
58-
//| Read one byte from PS/2 keyboard and turn on Scroll Lock LED::
60+
//| import ps2io
61+
//| import board
5962
//|
60-
//| import ps2io
61-
//| import board
63+
//| kbd = ps2io.Ps2(board.D10, board.D11)
6264
//|
63-
//| kbd = ps2io.Ps2(board.D10, board.D11)
65+
//| while len(kbd) == 0:
66+
//| pass
6467
//|
65-
//| while len(kbd) == 0:
66-
//| pass
67-
//|
68-
//| print(kbd.popleft())
69-
//| print(kbd.sendcmd(0xed))
70-
//| print(kbd.sendcmd(0x01))
68+
//| print(kbd.popleft())
69+
//| print(kbd.sendcmd(0xed))
70+
//| print(kbd.sendcmd(0x01))"""
71+
//| ...
7172
//|
7273
STATIC mp_obj_t ps2io_ps2_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
7374
enum { ARG_datapin, ARG_clkpin };
@@ -89,9 +90,9 @@ STATIC mp_obj_t ps2io_ps2_make_new(const mp_obj_type_t *type, size_t n_args, con
8990
return MP_OBJ_FROM_PTR(self);
9091
}
9192

92-
//| .. method:: deinit()
93-
//|
94-
//| Deinitialises the Ps2 and releases any hardware resources for reuse.
93+
//| def deinit(self, ) -> Any:
94+
//| """Deinitialises the Ps2 and releases any hardware resources for reuse."""
95+
//| ...
9596
//|
9697
STATIC mp_obj_t ps2io_ps2_deinit(mp_obj_t self_in) {
9798
ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -106,16 +107,16 @@ STATIC void check_for_deinit(ps2io_ps2_obj_t *self) {
106107
}
107108
}
108109

109-
//| .. method:: __enter__()
110-
//|
111-
//| No-op used by Context Managers.
110+
//| def __enter__(self, ) -> Any:
111+
//| """No-op used by Context Managers."""
112+
//| ...
112113
//|
113114
// Provided by context manager helper.
114115

115-
//| .. method:: __exit__()
116-
//|
117-
//| Automatically deinitializes the hardware when exiting a context. See
118-
//| :ref:`lifetime-and-contextmanagers` for more info.
116+
//| def __exit__(self, ) -> Any:
117+
//| """Automatically deinitializes the hardware when exiting a context. See
118+
//| :ref:`lifetime-and-contextmanagers` for more info."""
119+
//| ...
119120
//|
120121
STATIC mp_obj_t ps2io_ps2_obj___exit__(size_t n_args, const mp_obj_t *args) {
121122
(void)n_args;
@@ -124,10 +125,10 @@ STATIC mp_obj_t ps2io_ps2_obj___exit__(size_t n_args, const mp_obj_t *args) {
124125
}
125126
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ps2io_ps2___exit___obj, 4, 4, ps2io_ps2_obj___exit__);
126127

127-
//| .. method:: popleft()
128-
//|
129-
//| Removes and returns the oldest received byte. When buffer
130-
//| is empty, raises an IndexError exception.
128+
//| def popleft(self, ) -> Any:
129+
//| """Removes and returns the oldest received byte. When buffer
130+
//| is empty, raises an IndexError exception."""
131+
//| ...
131132
//|
132133
STATIC mp_obj_t ps2io_ps2_obj_popleft(mp_obj_t self_in) {
133134
ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -141,18 +142,18 @@ STATIC mp_obj_t ps2io_ps2_obj_popleft(mp_obj_t self_in) {
141142
}
142143
MP_DEFINE_CONST_FUN_OBJ_1(ps2io_ps2_popleft_obj, ps2io_ps2_obj_popleft);
143144

144-
//| .. method:: sendcmd(byte)
145-
//|
146-
//| Sends a command byte to PS/2. Returns the response byte, typically
147-
//| the general ack value (0xFA). Some commands return additional data
148-
//| which is available through :py:func:`popleft()`.
145+
//| def sendcmd(self, byte: int) -> Any:
146+
//| """Sends a command byte to PS/2. Returns the response byte, typically
147+
//| the general ack value (0xFA). Some commands return additional data
148+
//| which is available through :py:func:`popleft()`.
149149
//|
150-
//| Raises a RuntimeError in case of failure. The root cause can be found
151-
//| by calling :py:func:`clear_errors()`. It is advisable to call
152-
//| :py:func:`clear_errors()` before :py:func:`sendcmd()` to flush any
153-
//| previous errors.
150+
//| Raises a RuntimeError in case of failure. The root cause can be found
151+
//| by calling :py:func:`clear_errors()`. It is advisable to call
152+
//| :py:func:`clear_errors()` before :py:func:`sendcmd()` to flush any
153+
//| previous errors.
154154
//|
155-
//| :param int byte: byte value of the command
155+
//| :param int byte: byte value of the command"""
156+
//| ...
156157
//|
157158
STATIC mp_obj_t ps2io_ps2_obj_sendcmd(mp_obj_t self_in, mp_obj_t ob) {
158159
ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -166,35 +167,35 @@ STATIC mp_obj_t ps2io_ps2_obj_sendcmd(mp_obj_t self_in, mp_obj_t ob) {
166167
}
167168
MP_DEFINE_CONST_FUN_OBJ_2(ps2io_ps2_sendcmd_obj, ps2io_ps2_obj_sendcmd);
168169

169-
//| .. method:: clear_errors()
170+
//| def clear_errors(self, ) -> Any:
171+
//| """Returns and clears a bitmap with latest recorded communication errors.
170172
//|
171-
//| Returns and clears a bitmap with latest recorded communication errors.
173+
//| Reception errors (arise asynchronously, as data is received):
172174
//|
173-
//| Reception errors (arise asynchronously, as data is received):
175+
//| 0x01: start bit not 0
174176
//|
175-
//| 0x01: start bit not 0
177+
//| 0x02: timeout
176178
//|
177-
//| 0x02: timeout
179+
//| 0x04: parity bit error
178180
//|
179-
//| 0x04: parity bit error
181+
//| 0x08: stop bit not 1
180182
//|
181-
//| 0x08: stop bit not 1
183+
//| 0x10: buffer overflow, newest data discarded
182184
//|
183-
//| 0x10: buffer overflow, newest data discarded
185+
//| Transmission errors (can only arise in the course of sendcmd()):
184186
//|
185-
//| Transmission errors (can only arise in the course of sendcmd()):
187+
//| 0x100: clock pin didn't go to LO in time
186188
//|
187-
//| 0x100: clock pin didn't go to LO in time
189+
//| 0x200: clock pin didn't go to HI in time
188190
//|
189-
//| 0x200: clock pin didn't go to HI in time
191+
//| 0x400: data pin didn't ACK
190192
//|
191-
//| 0x400: data pin didn't ACK
193+
//| 0x800: clock pin didn't ACK
192194
//|
193-
//| 0x800: clock pin didn't ACK
195+
//| 0x1000: device didn't respond to RTS
194196
//|
195-
//| 0x1000: device didn't respond to RTS
196-
//|
197-
//| 0x2000: device didn't send a response byte in time
197+
//| 0x2000: device didn't send a response byte in time"""
198+
//| ...
198199
//|
199200
STATIC mp_obj_t ps2io_ps2_obj_clear_errors(mp_obj_t self_in) {
200201
ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -204,10 +205,10 @@ STATIC mp_obj_t ps2io_ps2_obj_clear_errors(mp_obj_t self_in) {
204205
}
205206
MP_DEFINE_CONST_FUN_OBJ_1(ps2io_ps2_clear_errors_obj, ps2io_ps2_obj_clear_errors);
206207

207-
//| .. method:: __len__()
208-
//|
209-
//| Returns the number of received bytes in buffer, available
210-
//| to :py:func:`popleft()`.
208+
//| def __len__(self, ) -> Any:
209+
//| """Returns the number of received bytes in buffer, available
210+
//| to :py:func:`popleft()`."""
211+
//| ...
211212
//|
212213
STATIC mp_obj_t ps2_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
213214
ps2io_ps2_obj_t *self = MP_OBJ_TO_PTR(self_in);

shared-bindings/ps2io/__init__.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "shared-bindings/microcontroller/Pin.h"
3434
#include "shared-bindings/ps2io/Ps2.h"
3535

36-
//| :mod:`ps2io` --- Support for PS/2 protocol
36+
//| """:mod:`ps2io` --- Support for PS/2 protocol
3737
//| =====================================================
3838
//|
3939
//| .. module:: ps2io
@@ -57,7 +57,7 @@
5757
//| All classes change hardware state and should be deinitialized when they
5858
//| are no longer needed if the program continues after use. To do so, either
5959
//| call :py:meth:`!deinit` or use a context manager. See
60-
//| :ref:`lifetime-and-contextmanagers` for more info.
60+
//| :ref:`lifetime-and-contextmanagers` for more info."""
6161
//|
6262

6363
STATIC const mp_rom_map_elem_t ps2io_module_globals_table[] = {

0 commit comments

Comments
 (0)