Variable-characteristic p—n-junction devices based on reversible ion drift