Skip to content

Add pinMode type #583

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

Merged
merged 1 commit into from
Oct 5, 2020
Merged

Add pinMode type #583

merged 1 commit into from
Oct 5, 2020

Conversation

ogatatsu
Copy link
Collaborator

Add the following pinMode types

  • INPUT_SENSE_HIGH
  • INPUT_SENSE_LOW
  • OUTPUT_S0S1
  • OUTPUT_H0S1
  • OUTPUT_S0H1
  • OUTPUT_H0H1
  • OUTPUT_D0S1
  • OUTPUT_D0H1
  • OUTPUT_S0D1
  • OUTPUT_H0D1

@ogatatsu
Copy link
Collaborator Author

ogatatsu commented Oct 3, 2020

The source of the firmata library is written assuming that the definition of INPUT is 0 and OUTPUT is 1, so I modified it to maintain compatibility.

Copy link
Member

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, it is indeed much easier to work with other libraries, since they expect the norm value. It is a bit more work with switch case, but compatible is more important.

@hathach hathach merged commit 4d703b6 into adafruit:master Oct 5, 2020
@ogatatsu ogatatsu deleted the pinMode branch October 5, 2020 10:45
@selman-nus
Copy link

Hi, which file should I include to be able to use OUTPUT_H0H1 in my sketch? I included <bluefruit.h> but Arduino is not happy yet.

error: 'OUTPUT_H0H1' was not declared in this scope
   50 |     pinMode(20, OUTPUT_H0H1);
      |                 ^~~~~~~~~~~
exit status 1
'OUTPUT_H0H1' was not declared in this scope

@selman-nus
Copy link

selman-nus commented Mar 9, 2021

@ogatatsu @hathach
I tried several files to include but it didn't work. So I copied the snippet to test it out.
.
Here is my code on setup(). I connected a sensor and tried to draw 9-10 ma of current. I measured current flow using a multimeter and I could only get 6mA from the pin. So I don't think the below snippet is functional.
.
Please let me know if I am missing something.

    uint32_t ulPin = 23;
    ulPin = g_ADigitalPinMap[ulPin];
    NRF_GPIO_Type * port = nrf_gpio_pin_port_decode(&ulPin);
    port->PIN_CNF[ulPin] = ((uint32_t)GPIO_PIN_CNF_DIR_Output       << GPIO_PIN_CNF_DIR_Pos)
                           | ((uint32_t)GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
                           | ((uint32_t)GPIO_PIN_CNF_PULL_Disabled    << GPIO_PIN_CNF_PULL_Pos)
                           | ((uint32_t)GPIO_PIN_CNF_DRIVE_H0H1       << GPIO_PIN_CNF_DRIVE_Pos)
                           | ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled   << GPIO_PIN_CNF_SENSE_Pos);
                           
    digitalWrite(ulPin, HIGH);
    delay(50);

.
I should be able to draw more than 10mA with the high drive setting.

image

pg156 nRF52832 Product Specification pdf

@ogatatsu
Copy link
Collaborator Author

Hi

Hi, which file should I include to be able to use OUTPUT_H0H1 in my sketch? I included <bluefruit.h> but Arduino is not happy yet.

It still doesn't work in version 0.21.0. I think it will work from the next version.

Please let me know if I am missing something.

How about this snippet?

    uint32_t ulPin = 23;
    uint32_t rawPin = g_ADigitalPinMap[ulPin];
    NRF_GPIO_Type * port = nrf_gpio_pin_port_decode(&rawPin);
    port->PIN_CNF[rawPin] = ((uint32_t)GPIO_PIN_CNF_DIR_Output       << GPIO_PIN_CNF_DIR_Pos)
                           | ((uint32_t)GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
                           | ((uint32_t)GPIO_PIN_CNF_PULL_Disabled    << GPIO_PIN_CNF_PULL_Pos)
                           | ((uint32_t)GPIO_PIN_CNF_DRIVE_H0H1       << GPIO_PIN_CNF_DRIVE_Pos)
                           | ((uint32_t)GPIO_PIN_CNF_SENSE_Disabled   << GPIO_PIN_CNF_SENSE_Pos);
                           
    digitalWrite(ulPin, HIGH);

@selman-nus
Copy link

Hi @ogatatsu ,
Thanks for the reply, I tried your snippet with my sensor again and it didn't work. The sensor is using just several mA on average but probably has high spikes on the startup. So I will test this snippet again in a more controlled way.
.
Is this repo not being updated anymore? I have seen your PR for spi.setpin() function and it is also not included in the current release. It seems like @hathach is not supporting here anymore.
.
Can you tell me how can I use your unreleased PRs? Is there a way to download them into my library?
I hope changing individual files one by one is not the only option for this purpose.

@jpconstantineau
Copy link
Contributor

There has been quite a few PRs that have been merged in. However, I suspect a release is no-where close because of issue #600
If you try using the master branch directly in your project (by following the steps indicated for development in the readme.md), you might be able to use the new features that have been brought in but you will also bring in the aforementioned issue.

@selman-nus
Copy link

@ladyada
Is it possible to get support on this issue?

@ladyada
Copy link
Member

ladyada commented Mar 18, 2021

this isnt an issue, its a PR - if you hav an issue you can open one, we have no guarantees of support for PRs made by others. you should probably just use a transistor to power the sensor not a pin.

@selman-nus
Copy link

@ladyada
Sorry i should have asked more clearly, I meant the issue just mentioned by @jpconstantineau , issue number #600 .
.
I already posted a message on that issue so i didn't wanted to double my message.
.
If this issue can be solved, we can use master branch directly in our projects with updated libraries.

@wb8wka
Copy link

wb8wka commented Mar 31, 2021

I have a similar issue with hardware PWM. In this case, I am using a transistor (Mosfet) to drive my load, however, due to the relatively high input capacitance of the MOSFET, I'd like to use OUTPUT_H0H1 to decrease my slew rate.

I tried the method @ogatatsu suggested as well as:

nrf_gpio_cfg(ulPin,
NRF_GPIO_PIN_DIR_OUTPUT,
NRF_GPIO_PIN_INPUT_CONNECT,
NRF_GPIO_PIN_NOPULL,
NRF_GPIO_PIN_H0H1,
NRF_GPIO_PIN_NOSENSE); // Hopefully this overrides the pinMode(pin, OUTPUT); in HardwarePWM.cpp

from: #361 (use high drive H0H1 for SCK and MOSI for better performance at highseed 32Mhz)

and it compiles and runs as before, with no change in the slew rate. I did check hardwarePWM.ccp to see if did another pinMode and it didn't appear to

Any other thoughts for workarounds?

Jeff

 void init_pwm(void)
 {
  uint32_t ulPin = IR_LED;     // Pin 11
  HwPWM0.addPin(IR_LED);   

 nrf_gpio_cfg(ulPin,
               NRF_GPIO_PIN_DIR_OUTPUT,
               NRF_GPIO_PIN_INPUT_CONNECT,
               NRF_GPIO_PIN_NOPULL,
               NRF_GPIO_PIN_H0H1,
               NRF_GPIO_PIN_NOSENSE);     // Hopefully this overrides the pinMode(pin, OUTPUT); in HardwarePWM.cpp

  HwPWM0.begin();
  HwPWM0.setResolution(6);
  HwPWM0.setClockDiv(PWM_PRESCALER_PRESCALER_DIV_1); // freq = 16Mhz
  HwPWM0.setMaxValue(35);
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants