My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pinmapping.cpp 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifdef TARGET_LPC1768
  23. #include <pinmapping.h>
  24. #include "../../../gcode/parser.h"
  25. // Get the digital pin for an analog index
  26. pin_t analogInputToDigitalPin(const int8_t p) {
  27. return (WITHIN(p, 0, NUM_ANALOG_INPUTS) ? adc_pin_table[p] : P_NC);
  28. }
  29. // Return the index of a pin number
  30. // The pin number given here is in the form ppp:nnnnn
  31. int16_t GET_PIN_MAP_INDEX(const pin_t pin) {
  32. const uint16_t index = (LPC1768_PIN_PORT(pin) << 5) | LPC1768_PIN_PIN(pin);
  33. return (index < NUM_DIGITAL_PINS && pin_map[index] != P_NC) ? index : -1;
  34. }
  35. // Test whether the pin is valid
  36. bool VALID_PIN(const pin_t p) {
  37. const int16_t ind = GET_PIN_MAP_INDEX(p);
  38. return ind >= 0 && pin_map[ind] >= 0;
  39. }
  40. // Get the analog index for a digital pin
  41. int8_t DIGITAL_PIN_TO_ANALOG_PIN(const pin_t p) {
  42. return (VALID_PIN(p) ? LPC1768_PIN_ADC(p) : -1);
  43. }
  44. // Test whether the pin is PWM
  45. bool PWM_PIN(const pin_t p) {
  46. return VALID_PIN(p) && LPC1768_PIN_PWM(p);
  47. }
  48. // Test whether the pin is interruptable
  49. bool INTERRUPT_PIN(const pin_t p) {
  50. return VALID_PIN(p) && LPC1768_PIN_INTERRUPT(p);
  51. }
  52. // Get the pin number at the given index
  53. pin_t GET_PIN_MAP_PIN(const int16_t ind) {
  54. return WITHIN(ind, 0, NUM_DIGITAL_PINS - 1) ? pin_map[ind] : P_NC;
  55. }
  56. int16_t PARSED_PIN_INDEX(const char code, const int16_t dval) {
  57. const uint16_t val = (uint16_t)parser.intval(code), port = val / 100, pin = val % 100;
  58. const int16_t ind = (port < (NUM_DIGITAL_PINS >> 5) && (pin < 32))
  59. ? GET_PIN_MAP_INDEX(port << 5 | pin) : -2;
  60. return ind > -2 ? ind : dval;
  61. }
  62. #endif // TARGET_LPC1768