Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from ronisbr:master #5

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
- 'nightly'
os:
- ubuntu-latest
- macos-latest
- windows-latest
arch:
- x64
steps:
Expand Down
28 changes: 4 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ jobs:
fail-fast: false
matrix:
version:
- '1.5'
- '1'
- '1.6'
- '1' # This automatically expands to the latest stable 1.x release.
os:
- ubuntu-latest
- macos-latest
- windows-latest
arch:
- x64
steps:
Expand All @@ -39,25 +41,3 @@ jobs:
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1'
- run: |
julia --project=docs -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()'
- run: |
julia --project=docs -e '
using Documenter: doctest
using BaremetalPi
doctest(BaremetalPi)'
- run: julia --project=docs docs/make.jl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
22 changes: 22 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Documentation
on:
push:
branches:
- master
tags: '*'
pull_request:

jobs:
docs:
name: Documenter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1'
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-docdeploy@releases/v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
BaremetalPi.jl Changelog
========================

Version 0.2.0
-------------

- ![BREAKING][badge-breaking] The `@assert`s were removed and changed to
conditionals. This modification can change the behavior of the code in some
corner cases. However, the code is more robust.
- ![Bug][badge-bugfix] IOCTL calls were not working with structures (pointers),
leading to problems when using SPI.


Version 0.1.2
-------------

- ![Bug][badge-bugfix] BaremetalPi.jl is now compatible with Julia 1.7.

Version 0.1.1
-------------

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BaremetalPi"
uuid = "3a90a9a9-52f9-452b-94bd-193d585bd84f"
authors = ["Ronan Arraes Jardim Chagas <[email protected]>"]
version = "0.1.1"
version = "0.2.0"

[compat]
julia = "1"
Expand Down
3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

[compat]
Documenter = "~0.27"
6 changes: 3 additions & 3 deletions docs/src/man/examples/temperature.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function acquire_temperature()
end

# AD measurement.
V = ( (UInt16(rx_buf[2] & 3) << 8) + rx_buf[3] )*3.3/1024
V = ((UInt16(rx_buf[2] & 3) << 8) + rx_buf[3]) * 3.3 / 1024

if V == 0
@warn("The MCP3008 measured 0V.")
Expand All @@ -124,8 +124,8 @@ function acquire_temperature()
# Convert the measurement to temperature
# ==========================================================================

th_R = R_div*(3.3/V - 1)
T = 1/( log(th_R / th_R₀)/th_β + 1/(th_T₀ + 273.15) ) - 273.15
th_R = R_div * (3.3 / V - 1)
T = 1 / (log(th_R / th_R₀) / th_β + 1 / (th_T₀ + 273.15)) - 273.15

return T
end
Expand Down
83 changes: 48 additions & 35 deletions src/cmacros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ const _IOC_DIRSHIFT = (_IOC_SIZESHIFT+_IOC_SIZEBITS)
const _IOC_WRITE = UInt32(1)
const _IOC_READ = UInt32(2)

_IOC(dir,type,nr,size) = (dir << _IOC_DIRSHIFT) |
(type << _IOC_TYPESHIFT) |
(nr << _IOC_NRSHIFT) |
(size << _IOC_SIZESHIFT)
function _IOC(dir, type, nr, size)
return (dir << _IOC_DIRSHIFT) |
(type << _IOC_TYPESHIFT) |
(nr << _IOC_NRSHIFT) |
(size << _IOC_SIZESHIFT)
end

_IOW(type,nr,size) = _IOC(_IOC_WRITE, type, nr, size)
_IOR(type,nr,size) = _IOC(_IOC_READ, type, nr, size)
_IOW(type, nr, size) = _IOC(_IOC_WRITE, type, nr, size)
_IOR(type, nr, size) = _IOC(_IOC_READ, type, nr, size)

################################################################################
# I2C
Expand Down Expand Up @@ -82,31 +84,38 @@ const I2C_FUNC_SMBUS_READ_I2C_BLOCK = 0x04000000
const I2C_FUNC_SMBUS_WRITE_I2C_BLOCK = 0x08000000
const I2C_FUNC_SMBUS_HOST_NOTIFY = 0x10000000

const I2C_FUNC_SMBUS_BYTE = (I2C_FUNC_SMBUS_READ_BYTE |
I2C_FUNC_SMBUS_WRITE_BYTE)
const I2C_FUNC_SMBUS_BYTE_DATA = (I2C_FUNC_SMBUS_READ_BYTE_DATA |
I2C_FUNC_SMBUS_WRITE_BYTE_DATA)
const I2C_FUNC_SMBUS_WORD_DATA = (I2C_FUNC_SMBUS_READ_WORD_DATA |
I2C_FUNC_SMBUS_WRITE_WORD_DATA)
const I2C_FUNC_SMBUS_BLOCK_DATA = (I2C_FUNC_SMBUS_READ_BLOCK_DATA |
I2C_FUNC_SMBUS_WRITE_BLOCK_DATA)
const I2C_FUNC_SMBUS_I2C_BLOCK = (I2C_FUNC_SMBUS_READ_I2C_BLOCK |
I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)

const I2C_FUNC_SMBUS_EMUL = (I2C_FUNC_SMBUS_QUICK |
I2C_FUNC_SMBUS_BYTE |
I2C_FUNC_SMBUS_BYTE_DATA |
I2C_FUNC_SMBUS_WORD_DATA |
I2C_FUNC_SMBUS_PROC_CALL |
I2C_FUNC_SMBUS_WRITE_BLOCK_DATA |
I2C_FUNC_SMBUS_I2C_BLOCK |
I2C_FUNC_SMBUS_PEC)
const I2C_FUNC_SMBUS_BYTE = (I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE)

const I2C_SMBUS_BLOCK_MAX = UInt8(32)
const I2C_FUNC_SMBUS_BYTE_DATA = (
I2C_FUNC_SMBUS_READ_BYTE_DATA | I2C_FUNC_SMBUS_WRITE_BYTE_DATA
)

const I2C_FUNC_SMBUS_WORD_DATA = (
I2C_FUNC_SMBUS_READ_WORD_DATA | I2C_FUNC_SMBUS_WRITE_WORD_DATA
)

const I2C_FUNC_SMBUS_BLOCK_DATA = (
I2C_FUNC_SMBUS_READ_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
)

const I2C_FUNC_SMBUS_I2C_BLOCK = (
I2C_FUNC_SMBUS_READ_I2C_BLOCK | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
)

const I2C_FUNC_SMBUS_EMUL = (
I2C_FUNC_SMBUS_QUICK |
I2C_FUNC_SMBUS_BYTE |
I2C_FUNC_SMBUS_BYTE_DATA |
I2C_FUNC_SMBUS_WORD_DATA |
I2C_FUNC_SMBUS_PROC_CALL |
I2C_FUNC_SMBUS_WRITE_BLOCK_DATA |
I2C_FUNC_SMBUS_I2C_BLOCK |
I2C_FUNC_SMBUS_PEC
)

const I2C_SMBUS_BLOCK_MAX = UInt8(32)
const I2C_SMBUS_READ = 0x01
const I2C_SMBUS_WRITE = 0x00

const I2C_SMBUS_QUICK = UInt32(0)
const I2C_SMBUS_BYTE = UInt32(1)
const I2C_SMBUS_BYTE_DATA = UInt32(2)
Expand All @@ -126,10 +135,10 @@ const I2C_SMBUS_I2C_BLOCK_DATA = UInt32(8)
const SPI_CPHA = 0x01
const SPI_CPOL = 0x02

const SPI_MODE_0 = (0|0)
const SPI_MODE_1 = (0|SPI_CPHA)
const SPI_MODE_2 = (SPI_CPOL|0)
const SPI_MODE_3 = (SPI_CPOL|SPI_CPHA)
const SPI_MODE_0 = (0 | 0)
const SPI_MODE_1 = (0 | SPI_CPHA)
const SPI_MODE_2 = (SPI_CPOL | 0)
const SPI_MODE_3 = (SPI_CPOL | SPI_CPHA)

const SPI_CS_HIGH = 0x04
const SPI_LSB_FIRST = 0x08
Expand All @@ -140,16 +149,20 @@ const SPI_READY = 0x80

const SPI_IOC_MAGIC = UInt('k')

SPI_MSGSIZE(N) =
( N*sizeof(struct_spi_ioc_transfer) < (1 << _IOC_SIZEBITS) ) ?
N*sizeof(struct_spi_ioc_transfer) : 0
function SPI_MSGSIZE(N)
if (N * sizeof(struct_spi_ioc_transfer)) < (1 << _IOC_SIZEBITS)
return N * sizeof(struct_spi_ioc_transfer)
else
return 0
end
end

# In the past, we were using `NTuple{SPI_MSGSIZE(N), Cchar}` to create a type so
# that the function `_IOC_TYPECHECK(t) = sizeof(t)` could retrieve the correct
# size. However, this was causing 3 allocations. Thus, the system was simplified
# to avoid this. Now, the functions `_IOR` and `_IOW` must receive the size
# instead of the type as it was coded in the Kernel source.
SPI_IOC_MESSAGE(N) = _IOW(SPI_IOC_MAGIC, 0, sizeof(Cchar)*SPI_MSGSIZE(N))
SPI_IOC_MESSAGE(N) = _IOW(SPI_IOC_MAGIC, 0, sizeof(Cchar) * SPI_MSGSIZE(N))

const SPI_IOC_RD_MODE = _IOR(SPI_IOC_MAGIC, 1, sizeof(__u8))
const SPI_IOC_WR_MODE = _IOW(SPI_IOC_MAGIC, 1, sizeof(__u8))
Expand Down
38 changes: 21 additions & 17 deletions src/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,27 @@ const __u64 = UInt64

const GPIOMEM_SIZE = 1024

const GPIO_MODE_GET = Dict(0b000 => :in,
0b001 => :out,
0b100 => :alt0,
0b101 => :alt1,
0b110 => :alt2,
0b111 => :alt3,
0b011 => :alt4,
0b010 => :alt5)

const GPIO_MODE_SET = Dict(:in => 0b000,
:out => 0b001,
:alt0 => 0b100,
:alt1 => 0b101,
:alt2 => 0b110,
:alt3 => 0b111,
:alt4 => 0b011,
:alt5 => 0b010)
const GPIO_MODE_GET = Dict(
0b000 => :in,
0b001 => :out,
0b100 => :alt0,
0b101 => :alt1,
0b110 => :alt2,
0b111 => :alt3,
0b011 => :alt4,
0b010 => :alt5
)

const GPIO_MODE_SET = Dict(
:in => 0b000,
:out => 0b001,
:alt0 => 0b100,
:alt1 => 0b101,
:alt2 => 0b110,
:alt3 => 0b111,
:alt4 => 0b011,
:alt5 => 0b010
)

################################################################################
# SPI
Expand Down
Loading