Unverified Commit 39dc2e05 authored by serg3295's avatar serg3295 Committed by GitHub
Browse files

Fix bit, bthci, can, encoder, eth, i2s docs (#3432)

* Fix bit, bthci, can, encoder, eth, i2s docs

* Fix bit, mqtt, qrcodegen, sigma-delta, sodium, time docs.

* Add object name in http.md
parent 1927b22c
...@@ -9,166 +9,166 @@ Bit manipulation support, on 32bit integers. ...@@ -9,166 +9,166 @@ Bit manipulation support, on 32bit integers.
## bit.arshift() ## bit.arshift()
Arithmetic right shift a number equivalent to `value >> shift` in C. Arithmetic right shift a number equivalent to `value >> shift` in C.
####Syntax #### Syntax
`bit.arshift(value, shift)` `bit.arshift(value, shift)`
####Parameters #### Parameters
- `value` the value to shift - `value` the value to shift
- `shift` positions to shift - `shift` positions to shift
####Returns #### Returns
the number shifted right (arithmetically) the number shifted right (arithmetically)
## bit.band() ## bit.band()
Bitwise AND, equivalent to `val1 & val2 & ... & valn` in C. Bitwise AND, equivalent to `val1 & val2 & ... & valn` in C.
####Syntax #### Syntax
`bit.band(val1, val2 [, ... valn])` `bit.band(val1, val2 [, ... valn])`
####Parameters #### Parameters
- `val1` first AND argument - `val1` first AND argument
- `val2` second AND argument - `val2` second AND argument
- `...valn` ...nth AND argument - `...valn` ...nth AND argument
####Returns #### Returns
the bitwise AND of all the arguments (number) the bitwise AND of all the arguments (number)
## bit.bit() ## bit.bit()
Generate a number with a 1 bit (used for mask generation). Equivalent to `1 << position` in C. Generate a number with a 1 bit (used for mask generation). Equivalent to `1 << position` in C.
####Syntax #### Syntax
`bit.bit(position)` `bit.bit(position)`
####Parameters #### Parameters
`position` position of the bit that will be set to 1 `position` position of the bit that will be set to 1
####Returns #### Returns
a number with only one 1 bit at position (the rest are set to 0) a number with only one 1 bit at position (the rest are set to 0)
## bit.bnot() ## bit.bnot()
Bitwise negation, equivalent to `~value in C. Bitwise negation, equivalent to `~value in C.
####Syntax #### Syntax
`bit.bnot(value)` `bit.bnot(value)`
####Parameters #### Parameters
`value` the number to negate `value` the number to negate
####Returns #### Returns
the bitwise negated value of the number the bitwise negated value of the number
## bit.bor() ## bit.bor()
Bitwise OR, equivalent to `val1 | val2 | ... | valn` in C. Bitwise OR, equivalent to `val1 | val2 | ... | valn` in C.
####Syntax #### Syntax
`bit.bor(val1, val2 [, ... valn])` `bit.bor(val1, val2 [, ... valn])`
####Parameters #### Parameters
- `val1` first OR argument. - `val1` first OR argument.
- `val2` second OR argument. - `val2` second OR argument.
- `...valn` ...nth OR argument - `...valn` ...nth OR argument
####Returns #### Returns
the bitwise OR of all the arguments (number) the bitwise OR of all the arguments (number)
## bit.bxor() ## bit.bxor()
Bitwise XOR, equivalent to `val1 ^ val2 ^ ... ^ valn` in C. Bitwise XOR, equivalent to `val1 ^ val2 ^ ... ^ valn` in C.
####Syntax #### Syntax
`bit.bxor(val1, val2 [, ... valn])` `bit.bxor(val1, val2 [, ... valn])`
####Parameters #### Parameters
- `val1` first XOR argument - `val1` first XOR argument
- `val2` second XOR argument - `val2` second XOR argument
- `...valn` ...nth XOR argument - `...valn` ...nth XOR argument
####Returns #### Returns
the bitwise XOR of all the arguments (number) the bitwise XOR of all the arguments (number)
## bit.clear() ## bit.clear()
Clear bits in a number. Clear bits in a number.
####Syntax #### Syntax
`bit.clear(value, pos1 [, ... posn])` `bit.clear(value, pos1 [, ... posn])`
####Parameters #### Parameters
- `value` the base number - `value` the base number
- `pos1` position of the first bit to clear - `pos1` position of the first bit to clear
- `...posn` position of thet nth bit to clear - `...posn` position of thet nth bit to clear
####Returns #### Returns
the number with the bit(s) cleared in the given position(s) the number with the bit(s) cleared in the given position(s)
## bit.isclear() ## bit.isclear()
Test if a given bit is cleared. Test if a given bit is cleared.
####Syntax #### Syntax
`bit.isclear(value, position)` `bit.isclear(value, position)`
####Parameters #### Parameters
- `value` the value to test - `value` the value to test
- `position` bit position to test - `position` bit position to test
####Returns #### Returns
true if the bit at the given position is 0, false othewise `true` if the bit at the given position is 0, `false` othewise
## bit.isset() ## bit.isset()
Test if a given bit is set. Test if a given bit is set.
####Syntax #### Syntax
`bit.isset(value, position)` `bit.isset(value, position)`
####Parameters #### Parameters
- `value` the value to test - `value` the value to test
- `position` bit position to test - `position` bit position to test
####Returns #### Returns
true if the bit at the given position is 1, false otherwise `true` if the bit at the given position is 1, `false` otherwise
## bit.lshift() ## bit.lshift()
Left-shift a number, equivalent to `value << shift` in C. Left-shift a number, equivalent to `value << shift` in C.
####Syntax #### Syntax
`bit.lshift(value, shift)` `bit.lshift(value, shift)`
####Parameters #### Parameters
- `value` the value to shift - `value` the value to shift
- `shift` positions to shift - `shift` positions to shift
####Returns #### Returns
the number shifted left the number shifted left
## bit.rshift() ## bit.rshift()
Logical right shift a number, equivalent to `( unsigned )value >> shift` in C. Logical right shift a number, equivalent to `( unsigned )value >> shift` in C.
####Syntax #### Syntax
`bit.rshift(value, shift)` `bit.rshift(value, shift)`
####Parameters #### Parameters
- `value` the value to shift. - `value` the value to shift.
- `shift` positions to shift. - `shift` positions to shift.
####Returns #### Returns
the number shifted right (logically) the number shifted right (logically)
## bit.set() ## bit.set()
Set bits in a number. Set bits in a number.
####Syntax #### Syntax
`bit.set(value, pos1 [, ... posn ])` `bit.set(value, pos1 [, ... posn ])`
####Parameters #### Parameters
- `value` the base number. - `value` the base number.
- `pos1` position of the first bit to set. - `pos1` position of the first bit to set.
- `...posn` position of the nth bit to set. - `...posn` position of the nth bit to set.
####Returns #### Returns
the number with the bit(s) set in the given position(s) the number with the bit(s) set in the given position(s)
...@@ -11,7 +11,7 @@ Advertisements are an easy way of publishing sensor data to e.g. a ...@@ -11,7 +11,7 @@ Advertisements are an easy way of publishing sensor data to e.g. a
smartphone app. smartphone app.
# bthci.rawhci(hcibytes, callback) ## bthci.rawhci(hcibytes, callback)
Sends a raw HCI command to the BlueTooth controller. Sends a raw HCI command to the BlueTooth controller.
...@@ -63,7 +63,7 @@ bthci.reset(function(err) print(err or "Ok!") end) ...@@ -63,7 +63,7 @@ bthci.reset(function(err) print(err or "Ok!") end)
``` ```
# bthci.adv.enable(onoff, callback) ## bthci.adv.enable(onoff, callback)
Enables or disables BlueTooth LE advertisements. Enables or disables BlueTooth LE advertisements.
...@@ -86,7 +86,7 @@ bthci.adv.enable(1, function(err) print(err or "Ok!") end) ...@@ -86,7 +86,7 @@ bthci.adv.enable(1, function(err) print(err or "Ok!") end)
``` ```
# bthci.adv.setdata(advbytes, callback) ## bthci.adv.setdata(advbytes, callback)
Configures the data to advertise. Configures the data to advertise.
...@@ -109,7 +109,7 @@ bthci.adv.setdata(encoder.fromHex("080861626364656667"), function(err) print(err ...@@ -109,7 +109,7 @@ bthci.adv.setdata(encoder.fromHex("080861626364656667"), function(err) print(err
``` ```
# bthci.adv.setparams(paramtable, callback) ## bthci.adv.setparams(paramtable, callback)
Configures advertisement parameters. Configures advertisement parameters.
...@@ -118,21 +118,19 @@ Configures advertisement parameters. ...@@ -118,21 +118,19 @@ Configures advertisement parameters.
#### Parameters #### Parameters
- `paramtable` a table with zero or more of the following fields: - `paramtable` a table with zero or more of the following fields:
- `interval_min` value in units of 0.625ms. Default 0x0400 (0.64s). - `interval_min` value in units of 0.625ms. Default 0x0400 (0.64s).
- `interval_max` value in units of 0.625ms. Default 0x0800 (1.28s). - `interval_max` value in units of 0.625ms. Default 0x0800 (1.28s).
- `type` advertising type, one of following constants: - `type` advertising type, one of following constants:
- `bthci.adv.CONN_UNDIR`, the default (ADV_IND in BT spec) - `bthci.adv.CONN_UNDIR`, the default (ADV_IND in BT spec)
- `bthci.adv.CONN_DIR_HI` (ADV_DIRECT_IND, high duty cycle in the BT spec) - `bthci.adv.CONN_DIR_HI` (ADV_DIRECT_IND, high duty cycle in the BT spec)
- `bthci.adv.SCAN_UNDIR` (ADV_SCAN_IND in the BT spec) - `bthci.adv.SCAN_UNDIR` (ADV_SCAN_IND in the BT spec)
- `bthci.adv.NONCONN_UNDIR` (ADV_NONCONN_IND in the BT spec) - `bthci.adv.NONCONN_UNDIR` (ADV_NONCONN_IND in the BT spec)
- `bthci.adv.CONN_DIR_LO` (ADV_DIRECT_IND, low duty cycle in the BT spec) - `bthci.adv.CONN_DIR_LO` (ADV_DIRECT_IND, low duty cycle in the BT spec)
- `own_addr_type` own address type. Default 0 (public address). - `own_addr_type` own address type. Default 0 (public address).
- `peer_addr_type` peer address type. Default 0 (public address). - `peer_addr_type` peer address type. Default 0 (public address).
- `peer_addr` TODO, not yet implemented - `peer_addr` TODO, not yet implemented
- `channel_map` which channels to advertise on. The constants - `channel_map` which channels to advertise on. The constants `bthci.adv.CHAN_37`, `bthci.adv.CHAN_38`, `bthci.adv.CHAN_39` or `bthci.adv.CHAN_ALL` may be used. Default is all channels.
`bthci.adv.CHAN_37`, `bthci.adv.CHAN_38`, `bthci.adv.CHAN_39` or - `filter_policy` filter policy, default 0 (no filtering).
`bthci.adv.CHAN_ALL` may be used. Default is all channels.
- `filter_policy` filter policy, default 0 (no filtering).
- `callback` optional function to be invoked when the reset completes. Its - `callback` optional function to be invoked when the reset completes. Its
only argument is the HCI error code, or `nil` on success. only argument is the HCI error code, or `nil` on success.
...@@ -145,7 +143,7 @@ bthci.adv.setparams({type=bthci.adv.NONCONN_UNDIR}, function(err) print(err or " ...@@ -145,7 +143,7 @@ bthci.adv.setparams({type=bthci.adv.NONCONN_UNDIR}, function(err) print(err or "
``` ```
# bthci.scan.enable(onoff, callback) ## bthci.scan.enable(onoff, callback)
Enables or disable scanning for advertisements from other BlueTooth devices. Enables or disable scanning for advertisements from other BlueTooth devices.
...@@ -166,7 +164,7 @@ bthci.scan.enable(1, function(err) print(err or "Ok!") end) ...@@ -166,7 +164,7 @@ bthci.scan.enable(1, function(err) print(err or "Ok!") end)
``` ```
# bthci.scan.setparams(paramstable, callback) ## bthci.scan.setparams(paramstable, callback)
Configures scan parameters. Configures scan parameters.
...@@ -178,11 +176,11 @@ this will fully occupy the radio and no other activity takes place. ...@@ -178,11 +176,11 @@ this will fully occupy the radio and no other activity takes place.
#### Parameters #### Parameters
- `paramstable` a table with zero or more of the following fields: - `paramstable` a table with zero or more of the following fields:
- `mode` scanning mode, 0 for passive, 1 for active. Default 0. - `mode` scanning mode, 0 for passive, 1 for active. Default 0.
- `interval` scanning interval in units of 0.625ms. Default 0x0010. - `interval` scanning interval in units of 0.625ms. Default 0x0010.
- `window` length of scanning window in units of 0.625ms. Default 0x0010. - `window` length of scanning window in units of 0.625ms. Default 0x0010.
- `own_addr_type` own address type. Default 0 (public). - `own_addr_type` own address type. Default 0 (public).
- `filter_policy` filtering policy. Default 0 (no filtering). - `filter_policy` filtering policy. Default 0 (no filtering).
- `callback` optional function to be invoked when the reset completes. Its - `callback` optional function to be invoked when the reset completes. Its
only argument is the HCI error code, or `nil` on success. only argument is the HCI error code, or `nil` on success.
...@@ -194,7 +192,7 @@ this will fully occupy the radio and no other activity takes place. ...@@ -194,7 +192,7 @@ this will fully occupy the radio and no other activity takes place.
bthci.scan.setparams({mode=1,interval=40,window=20},function(err) print(err or "Ok!") end) bthci.scan.setparams({mode=1,interval=40,window=20},function(err) print(err or "Ok!") end)
``` ```
# bthci.scan.on(event, callback) ## bthci.scan.on(event, callback)
Registers the callback to be passed any received advertisements. Registers the callback to be passed any received advertisements.
......
...@@ -18,13 +18,32 @@ Send a frame. ...@@ -18,13 +18,32 @@ Send a frame.
- `data` CAN data, up to 8 bytes - `data` CAN data, up to 8 bytes
#### Returns #### Returns
nil `nil`
## can.setup() ## can.setup()
Configuration CAN controller. Configuration CAN controller.
#### Syntax #### Syntax
`can.setup(config, callback)`
#### Parameters
- `config` table.
- `speed` kbps. One of following value: `1000`, `800`, `500`, `250`, `100`.
- `tx` Pin num for TX.
- `rx` Pin num for RX.
- `dual_filter` `true` dual filter mode, `false` single filter mode (default)
- `code` 4-bytes integer. Use this with mask to filter CAN frame. Default: `0`. See [SJA1000](http://www.nxp.com/documents/data_sheet/SJA1000.pdf)
- `mask` 4-bytes integer. Default: `0xffffffff`
- `callback` function to be called when CAN data received.
- `format` Frame format. `can.STANDARD_FRAME` or `can.EXTENDED_FRAME`
- `msg_id` CAN Message ID
- `data` CAN data, up to 8 bytes
#### Returns
`nil`
#### Example
```lua ```lua
can.setup({ can.setup({
speed = 1000, speed = 1000,
...@@ -36,23 +55,6 @@ can.setup({ ...@@ -36,23 +55,6 @@ can.setup({
}, function(format, msg_id, data) end) }, function(format, msg_id, data) end)
``` ```
#### Parameters
- `config`
- `speed` kbps. One of following value: `1000`, `800`, `500`, `250`, `100`.
- `tx` Pin num for TX.
- `rx` Pin num for RX.
- `dual_filter` `true` dual filter mode, `false` single filter mode (default)
- `code` 4-bytes integer. Use this with mask to filter CAN frame. Default: `0`. See [SJA1000](http://www.nxp.com/documents/data_sheet/SJA1000.pdf)
- `mask` 4-bytes integer. Default: `0xffffffff`
- `callback` function to be called when CAN data received.
- `format` Frame format. `can.STANDARD_FRAME` or `can.EXTENDED_FRAME`
- `msg_id` CAN Messge ID
- `data` CAN data, up to 8 bytes
#### Returns
nil
## can.start() ## can.start()
Start CAN controller. Start CAN controller.
...@@ -60,9 +62,10 @@ Start CAN controller. ...@@ -60,9 +62,10 @@ Start CAN controller.
`can.start()` `can.start()`
#### Parameters #### Parameters
none
#### Returns #### Returns
nil `nil`
## can.stop() ## can.stop()
...@@ -72,6 +75,7 @@ Stop CAN controller. ...@@ -72,6 +75,7 @@ Stop CAN controller.
`can.stop()` `can.stop()`
#### Parameters #### Parameters
none
#### Returns #### Returns
nil `nil`
...@@ -15,7 +15,7 @@ Provides a Base64 representation of a (binary) Lua string. ...@@ -15,7 +15,7 @@ Provides a Base64 representation of a (binary) Lua string.
#### Parameters #### Parameters
`binary` input string to Base64 encode `binary` input string to Base64 encode
#### Return #### Returns
A Base64 encoded string. A Base64 encoded string.
#### Example #### Example
...@@ -34,7 +34,7 @@ thrown if the string is not a valid base64 encoding. ...@@ -34,7 +34,7 @@ thrown if the string is not a valid base64 encoding.
#### Parameters #### Parameters
`b64` Base64 encoded input string `b64` Base64 encoded input string
#### Return #### Returns
The decoded Lua (binary) string. The decoded Lua (binary) string.
#### Example #### Example
......
...@@ -46,7 +46,7 @@ Connection speed in Mbit/s, or error if not connected. ...@@ -46,7 +46,7 @@ Connection speed in Mbit/s, or error if not connected.
## eth.init() ## eth.init()
Initialize the PHY chip and set up its tcpip adapter. Initialize the PHY chip and set up its tcpip adapter.
#### Synatx #### Syntax
```lua ```lua
eth.init(cfg) eth.init(cfg)
``` ```
......
...@@ -30,7 +30,7 @@ Creates a connection object which can be configured and then executed. Note this ...@@ -30,7 +30,7 @@ Creates a connection object which can be configured and then executed. Note this
- `timeout` Network timeout, in milliseconds. If not specified, the default is `10000` (10 seconds). - `timeout` Network timeout, in milliseconds. If not specified, the default is `10000` (10 seconds).
#### Returns #### Returns
The connection object. `connection` The connection object.
#### Example #### Example
```lua ```lua
......
...@@ -16,7 +16,7 @@ The I2S module provides access to the in-built two I2S controllers. ...@@ -16,7 +16,7 @@ The I2S module provides access to the in-built two I2S controllers.
Mute the I2S channel. The hardware buffer is instantly filled with silence. Mute the I2S channel. The hardware buffer is instantly filled with silence.
#### Syntax #### Syntax
`i2s.mute(i2s_num) `i2s.mute(i2s_num)`
#### Parameters #### Parameters
- `i2s_num` I2S peripheral 0 or 1 - `i2s_num` I2S peripheral 0 or 1
......
...@@ -203,7 +203,7 @@ Publishes a message. ...@@ -203,7 +203,7 @@ Publishes a message.
#### Parameters #### Parameters
- `topic` the topic to publish to ([topic string](http://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices)) - `topic` the topic to publish to ([topic string](http://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices))
- `message` the message to publish, (buffer or string) - `payload` the message to publish, (buffer or string)
- `qos` QoS level - `qos` QoS level
- `retain` retain flag - `retain` retain flag
- `function(client)` optional callback fired when PUBACK received. NOTE: When calling publish() more than once, the last callback function defined will be called for ALL publish commands. - `function(client)` optional callback fired when PUBACK received. NOTE: When calling publish() more than once, the last callback function defined will be called for ALL publish commands.
......
...@@ -47,6 +47,9 @@ Returns the side length in pixels of the given QR Code. The result is in the ran ...@@ -47,6 +47,9 @@ Returns the side length in pixels of the given QR Code. The result is in the ran
## qrcodegen.getPixel(qrcode, x, y) ## qrcodegen.getPixel(qrcode, x, y)
Get the color of the pixel at the given coordinates of the QR Code. `x` and `y` must be between `0` and the value returned by `qrcodegen.getSize()`. Get the color of the pixel at the given coordinates of the QR Code. `x` and `y` must be between `0` and the value returned by `qrcodegen.getSize()`.
#### Syntax
`qrcodegen.getPixel(qrcode, x, y)`
#### Parameters #### Parameters
- `qrcode` a QR Code string, as returned by `qrcodegen.encodeText()`. - `qrcode` a QR Code string, as returned by `qrcodegen.encodeText()`.
- `x` - `x`
......
...@@ -23,7 +23,7 @@ Reenables GPIO functionality at the related pin. ...@@ -23,7 +23,7 @@ Reenables GPIO functionality at the related pin.
Sets the prescale value. Sets the prescale value.
#### Syntax #### Syntax
`sigma_delta.setprescale(channel, value) `sigma_delta.setprescale(channel, value)`
#### Parameters #### Parameters
- `channel` 0~7, sigma-delta channel index - `channel` 0~7, sigma-delta channel index
......
...@@ -56,6 +56,9 @@ The keys created by `crypto_box.keypair()` can be used the `crypto_box.seal*()` ...@@ -56,6 +56,9 @@ The keys created by `crypto_box.keypair()` can be used the `crypto_box.seal*()`
## sodium.crypto_box.keypair() ## sodium.crypto_box.keypair()
Generates a new keypair. Wifi must be started, by calling `wifi.start()`, before calling this function. Generates a new keypair. Wifi must be started, by calling `wifi.start()`, before calling this function.
#### Syntax
`sodium.crypto_box.keypair()`
#### Parameters #### Parameters
None None
...@@ -88,7 +91,7 @@ The encrypted message, as a string. Errors if `public_key` is not a valid public ...@@ -88,7 +91,7 @@ The encrypted message, as a string. Errors if `public_key` is not a valid public
ciphertext = sodium.crypto_box.seal(message, public_key) ciphertext = sodium.crypto_box.seal(message, public_key)
``` ```
## sodium.crypto_box.seal_open ## sodium.crypto_box.seal_open()
Decrypts a message encrypted with [`crypto_box.seal()`](#sodiumcryptoboxseal). Decrypts a message encrypted with [`crypto_box.seal()`](#sodiumcryptoboxseal).
#### Syntax #### Syntax
......
...@@ -43,7 +43,7 @@ time.set(timestamp) ...@@ -43,7 +43,7 @@ time.set(timestamp)
Converts timestamp in Unix epoch to calendar format Converts timestamp in Unix epoch to calendar format
#### Syntax #### Syntax
`time.epoch2cal(time) `time.epoch2cal(time)`
#### Parameters #### Parameters
- `time` number of seconds since the Epoch - `time` number of seconds since the Epoch
...@@ -76,7 +76,7 @@ print(string.format("%04d-%02d-%02d %02d:%02d:%02d DST:%d", time["year"], time[" ...@@ -76,7 +76,7 @@ print(string.format("%04d-%02d-%02d %02d:%02d:%02d DST:%d", time["year"], time["
Returns current system time in the Unix epoch (seconds from midnight 1970/01/01). Returns current system time in the Unix epoch (seconds from midnight 1970/01/01).
#### Syntax #### Syntax
time.get() `time.get()`
#### Parameters #### Parameters
none none
...@@ -100,7 +100,7 @@ sec, usec = time.get() ...@@ -100,7 +100,7 @@ sec, usec = time.get()
Returns current system time adjusted for the locale in calendar format. Returns current system time adjusted for the locale in calendar format.
#### Syntax #### Syntax
time.getlocal() `time.getlocal()`
#### Parameters #### Parameters
none none
...@@ -155,7 +155,7 @@ Checks if NTP client is enabled. ...@@ -155,7 +155,7 @@ Checks if NTP client is enabled.
none none
#### Returns #### Returns
`true' if NTP client is enabled. `true` if NTP client is enabled.
## time.ntpstop() ## time.ntpstop()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment