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

Added support for driving the aux-spi port. #146

Open
wants to merge 1 commit 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
54 changes: 54 additions & 0 deletions lib/rpio.js
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,60 @@ rpio.prototype.spiEnd = function()
{
bindcall(binding.spi_end);
}
/*
* AUX_SPI
*/
rpio.prototype.auxSpiBegin = function()
{
if (!rpio_inited) {
/* SPI requires full /dev/mem */
rpio_options.gpiomem = false;
rpio.prototype.init();
}

if (rpio_options.gpiomem)
throw new Error('SPI not available in gpiomem mode');

bindcall(binding.aux_spi_begin);
}

rpio.prototype.auxSpiChipSelect = function(cs)
{
return bindcall(binding.aux_spi_chip_select, cs);
}

rpio.prototype.auxSpiSetCSPolarity = function(cs, active)
{
return bindcall2(binding.aux_spi_set_cs_polarity, cs, active);
}

rpio.prototype.auxSpiSetClockDivider = function(divider)
{
if ((divider % 2) !== 0 || divider < 0 || divider > 65536)
throw new Error('Clock divider must be an even number between 0 and 65536');

return bindcall(binding.aux_spi_set_clock_divider, divider);
}

rpio.prototype.auxSpiSetDataMode = function(mode)
{
return bindcall(binding.aux_spi_set_data_mode, mode);
}

rpio.prototype.auxSpiTransfer = function(txbuf, rxbuf, len)
{
return bindcall3(binding.aux_spi_transfer, txbuf, rxbuf, len);
}

rpio.prototype.auxSpiWrite = function(buf, len)
{
return bindcall2(binding.aux_spi_write, buf, len);
}

rpio.prototype.auxSpiEnd = function()
{
bindcall(binding.aux_spi_end);
}

/*
* Misc functions.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rpio",
"version": "2.4.2",
"version": "2.4.3",
"description": "High performance GPIO/i2c/PWM/SPI module for Raspberry Pi, Orange Pi, Banana Pi",
"homepage": "https://www.npmjs.com/package/rpio",
"main": "./lib/rpio.js",
Expand Down
84 changes: 84 additions & 0 deletions src/rpio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,77 @@ NAN_METHOD(spi_end)
{
bcm2835_spi_end();
}
/*
* AUX_SPI functions.
*/
NAN_METHOD(aux_spi_begin)
{
bcm2835_aux_spi_begin();
}

// NAN_METHOD(aux_spi_chip_select)
// {
// ASSERT_ARGC1(IS_U32);

// uint32_t cs = FROM_U32(0);

// bcm2835_aux_spi_chipSelect(cs);
// }

// NAN_METHOD(aux_spi_set_cs_polarity)
// {
// ASSERT_ARGC2(IS_U32, IS_U32);

// uint32_t cs = FROM_U32(0);
// uint32_t active = FROM_U32(1);

// bcm2835_aux_spi_setChipSelectPolarity(cs, active);
// }

NAN_METHOD(aux_spi_set_clock_divider)
{
ASSERT_ARGC1(IS_U32);

uint32_t divider = FROM_U32(0);

bcm2835_aux_spi_setClockDivider(divider);
}

// NAN_METHOD(aux_spi_set_data_mode)
// {
// ASSERT_ARGC1(IS_U32);

// uint32_t mode = FROM_U32(0);

// bcm2835_aux_spi_setDataMode(mode);
// }

NAN_METHOD(aux_spi_transfer)
{
ASSERT_ARGC3(IS_OBJ, IS_OBJ, IS_U32);

char *tbuf = FROM_OBJ(0);
char *rbuf = FROM_OBJ(1);
uint32_t len = FROM_U32(2);

bcm2835_aux_spi_transfernb(tbuf, rbuf, len);
}

NAN_METHOD(aux_spi_write)
{
ASSERT_ARGC2(IS_OBJ, IS_U32);

char *buf = FROM_OBJ(0);
uint32_t len = FROM_U32(1);

bcm2835_aux_spi_writenb(buf, len);
}

NAN_METHOD(aux_spi_end)
{
bcm2835_aux_spi_end();
}


/*
* Initialize the bcm2835 interface and check we have permission to access it.
Expand Down Expand Up @@ -584,6 +655,14 @@ NAN_MODULE_INIT(setup)
NAN_EXPORT(target, spi_transfer);
NAN_EXPORT(target, spi_write);
NAN_EXPORT(target, spi_end);
NAN_EXPORT(target, aux_spi_begin);
// NAN_EXPORT(target, aux_spi_chip_select);
// NAN_EXPORT(target, aux_spi_set_cs_polarity);
NAN_EXPORT(target, aux_spi_set_clock_divider);
// NAN_EXPORT(target, aux_spi_set_data_mode);
NAN_EXPORT(target, aux_spi_transfer);
NAN_EXPORT(target, aux_spi_write);
NAN_EXPORT(target, aux_spi_end);
}

#else /* __linux__ */
Expand All @@ -597,4 +676,9 @@ NAN_MODULE_INIT(setup)

#endif

#if NODE_MAJOR_VERSION >= 10
NAN_MODULE_WORKER_ENABLED(rpio, setup)
#else
NODE_MODULE(rpio, setup)
#endif